From 0e926ee280e976980a6b81d107a9a8c25b1118af Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 07:02:28 +0000 Subject: [PATCH 001/132] Auto-generated commit d43ec5cdf0ab9615d75390818b7b5e9ebe1b18dc --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 468 +++++++++ index.d.ts | 436 ++++++++ index.mjs | 4 + index.mjs.map | 1 + package.json | 44 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 4152 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..e5c157f --- /dev/null +++ b/README.md @@ -0,0 +1,468 @@ + + +# mapKeysAsync + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Map keys from one object to a new object having the same values. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; +``` + +#### mapKeysAsync( obj, \[options,] transform, done ) + +Map keys from one `object` to a new `object` having the same values. + +```javascript +function transform( key, next ) { + setTimeout( onTimeout, 0 ); + function onTimeout() { + next( null, key+':beep' ); + } +} + +function done( error, out ) { + if ( error ) { + throw error; + } + console.log( out ); + // => { 'a:beep': 1, 'b:beep': 2 } +} + +var obj = { + 'a': 1, + 'b': 2 +}; + +mapKeysAsync( obj, transform, done ); +``` + +The `next` callback accepts two arguments: `error` and `key`. The second argument to the `next` callback is the transformed property name. If a `transform` function calls the `next` callback with a truthy error argument, the function stops processing any additional own properties and calls the `done` callback for error processing. + +```javascript +function transform( key, value, next ) { + setTimeout( onTimeout, value ); + function onTimeout() { + if ( value === 1 ) { + return next( new Error( 'boop' ) ); + } + next( null, key+':beep' ); + } +} + +function done( error ) { + if ( error ) { + console.error( error.message ); + // => 'boop' + } +} + +var obj = { + 'a': 1, + 'b': 2 +}; + +mapKeysAsync( obj, transform, done ); +``` + +The function accepts the following `options`: + +- `limit`: the maximum number of pending invocations at any one time. Default: `infinity`. +- `series`: `boolean` indicating whether to sequentially invoke the `transform` function for each own property. If `true`, the function sets `options.limit=1`. Default: `false`. +- `thisArg`: the execution context for `fcn`. + +By default, all properties are processed concurrently, which means that the function does **not** guarantee completion order. To process each property sequentially, set the `series` option to `true`. + +```javascript +function transform( key, value, next ) { + setTimeout( onTimeout, value ); + function onTimeout() { + next( null, key+':beep' ); + } +} + +function done( error, out ) { + if ( error ) { + throw error; + } + console.log( out ); + // => { 'a:beep': 1, 'b:beep': 2 } +} + +var obj = { + 'a': 1, + 'b': 2 +}; + +var opts = { + 'series': true +}; + +mapKeysAsync( obj, opts, transform, done ); +``` + +To limit the maximum number of pending function invocations, set the `limit` option. + +```javascript +function transform( key, value, next ) { + setTimeout( onTimeout, value ); + function onTimeout() { + next( null, key+':beep' ); + } +} + +function done( error, out ) { + if ( error ) { + throw error; + } + console.log( out ); + // => { 'a:beep': 1, 'b:beep': 2, 'c:beep': 3 } +} + +var obj = { + 'a': 1, + 'b': 2, + 'c': 3 +}; + +var opts = { + 'limit': 2 +}; + +mapKeysAsync( obj, opts, transform, done ); +``` + +To set the execution context of the `transform` function, set the `thisArg` option. + +```javascript +function transform( key, value, next ) { + this.count += 1; + setTimeout( onTimeout, value ); + function onTimeout() { + next( null, key+':beep' ); + } +} + +var obj = { + 'a': 1, + 'b': 2, + 'c': 3 +}; + +var context = { + 'count': 0 +}; + +var opts = { + 'thisArg': context +}; + +mapKeysAsync( obj, opts, transform, done ); + +function done( error, out ) { + if ( error ) { + throw error; + } + console.log( out ); + // => { 'a:beep': 1, 'b:beep': 2, 'c:beep': 3 } + + console.log( context.count ); + // => 3 +} +``` + +When invoked, the `transform` function is provided a maximum of four arguments: + +- `key`: object key. +- `value`: object value corresponding to `key`. +- `obj`: source object. +- `next`: a callback which should be called once the `transform` function has finished processing a property. + +The actual number of provided arguments depends on function `length`. If the `transform` function accepts two arguments, the `transform` function is provided `key` and `next`. If the `transform` function accepts three arguments, the `transform` function is provided `key`, `value`, and `next`. For every other `transform` function signature, the `transform` function is provided all four arguments. + +```javascript +function transform( key, value, obj, next ) { + console.log( 'obj: %s. %s: %d', JSON.stringify( obj ), key, value ); + setTimeout( onTimeout, value ); + function onTimeout() { + next( null, key+':'+value ); + } +} + +function done( error, out ) { + if ( error ) { + throw error; + } + console.log( out ); +} + +var obj = { + 'a': 1, + 'b': 2 +}; + +mapKeysAsync( obj, transform, done ); +/* => e.g., + obj: {"a": 1, "b": 2}. a: 1 + obj: {"a": 1, "b": 2}. b: 2 + { 'a:1': 1, 'b:2': 2 } +*/ +``` + +#### mapKeysAsync.factory( \[options,] transform ) + +Returns a `function` which invokes a `transform` function once for each own property. + +```javascript +function transform( key, value, next ) { + setTimeout( onTimeout, value ); + function onTimeout() { + next( null, key+':beep' ); + } +} + +function done( error, out ) { + if ( error ) { + throw error; + } + console.log( out ); +} + +var f = mapKeysAsync.factory( transform ); + +var obj1 = { + 'a': 1, + 'b': 2 +}; + +f( obj1, done ); +// => { 'a:beep': 1, 'b:beep': 2 } + +var obj2 = { + 'c': 3, + 'd': 4 +}; + +f( obj2, done ); +// => { 'c:beep': 3, 'd:beep': 4 } +``` + +The function accepts the same `options` as `mapKeysAsync()`. + +
+ + + + + +
+ +## Notes + +- 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. +- If provided an empty `object`, the function calls the `done` callback with an empty `object`. +- Key iteration order is **not** guaranteed, as `object` key enumeration is not specified according to the [ECMAScript specification][ecma-262]. In practice, however, most engines use insertion order to sort an `object`'s keys, thus allowing for iteration order. +- Key insertion order is **not** guaranteed. +- The value returned by a `transform` function should be a value which can be serialized as an `object` key. +- The function only maps **own** properties. Hence, the function does **not** map inherited properties. +- The function **shallow** copies key values. +- **Neither** `mapKeysAsync` 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..284be58 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,436 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 + +/** +* 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 own property (default: false). + */ + series?: boolean; + + /** + * Execution context. + */ + thisArg?: any; +} + +/** +* Callback invoked upon completion. +*/ +type DoneNullary = () => void; + +/** +* Callback invoked upon completion. +* +* @param error - encountered error or null +*/ +type DoneUnary = ( error: Error | null ) => void; + +/** +* Callback invoked upon completion. +* +* @param error - encountered error or null +* @param out - output object +*/ +type DoneBinary = ( error: Error | null, out: any ) => void; + +/** +* Callback invoked upon completion. +* +* @param error - encountered error or null +* @param out - output object +*/ +type DoneCallback = DoneNullary | DoneUnary | DoneBinary; + +/** +* 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 group - value group +*/ +type Binary = ( error: Error | null, group: string ) => void; + +/** +* Callback function. +* +* @param error - encountered error or null +* @param group - value group +*/ +type Callback = Nullary | Unary | Binary; + +/** +* Transform function. +* +* @param key - object key +* @param next - a callback to be invoked after processing an object `value` +*/ +type BinaryTransform = ( value: any, next: Callback ) => void; + +/** +* Transform function. +* +* @param key - object key +* @param value - object value corresponding to `key` +* @param next - a callback to be invoked after processing an object `value` +*/ +type TernaryTransform = ( value: any, index: number, next: Callback ) => void; + +/** +* Transform function. +* +* @param key - object key +* @param value - object value corresponding to `key` +* @param obj - the input object +* @param next - a callback to be invoked after processing an object `value` +*/ +type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length + +/** +* Transform function. +* +* @param key - object key +* @param value - object value corresponding to `key` +* @param obj - the input object +* @param next - a callback to be invoked after processing an object `value` +*/ +type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length + +/** +* Maps keys from one object to a new object having the same values. +* +* @param obj - the input object +* @param done - function to invoke upon completion +*/ +type FactoryFunction = ( obj: any, done: DoneCallback ) => void; + +/** +* Interface for `mapKeysAsync`. +*/ +interface MapKeysAsync { + /** + * Maps keys from one object to a new object having the same values. + * + * ## Notes + * + * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. + * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). + * - Iteration and insertion order are **not** guaranteed. + * - The function only operates on own properties, not inherited properties. + * + * + * @param obj - source object + * @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 own property (default: false) + * @param transform - transform function + * @param done - function to invoke upon completion + * @throws must provide valid options + * + * @example + * var readFile = require( `@stdlib/fs/read-file` ); + * + * function read( key, value, next ) { + * var opts = { + * 'encoding': 'utf8' + * }; + * readFile( value, opts, onFile ); + * + * function onFile( error ) { + * if ( error ) { + * return next( null, key+':unreadable' ); + * } + * next( null, key+':readable' ); + * } + * } + * + * // Define a callback which handles errors: + * function done( error, out ) { + * if ( error ) { + * throw error; + * } + * console.log( out ); + * } + * + * // Create a dictionary of file names: + * var files = { + * 'file1': './beep.js', + * 'file2': './boop.js' + * }; + * + * var opts = { + * 'series': true + * }; + * + * // Process each file in `files`: + * mapKeysAsync( files, opts, read, done ); + */ + ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length + + /** + * Maps keys from one object to a new object having the same values. + * + * ## Notes + * + * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. + * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). + * - Iteration and insertion order are **not** guaranteed. + * - The function only operates on own properties, not inherited properties. + * + * + * @param obj - source object + * @param transform - transform function + * @param done - function to invoke upon completion + * + * @example + * var readFile = require( `@stdlib/fs/read-file` ); + * + * function read( key, value, next ) { + * var opts = { + * 'encoding': 'utf8' + * }; + * readFile( value, opts, onFile ); + * + * function onFile( error ) { + * if ( error ) { + * return next( null, key+':unreadable' ); + * } + * next( null, key+':readable' ); + * } + * } + * + * // Define a callback which handles errors: + * function done( error, out ) { + * if ( error ) { + * throw error; + * } + * console.log( out ); + * } + * + * // Create a dictionary of file names: + * var files = { + * 'file1': './beep.js', + * 'file2': './boop.js' + * }; + * + * // Process each file in `files`: + * mapKeysAsync( files, read, done ); + */ + ( obj: any, transform: Transform, done: DoneCallback ): void; + + /** + * Returns a function to map keys from one object to a new object having the same values. + * + * ## Notes + * + * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. + * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). + * - Iteration and insertion order are **not** guaranteed. + * - The function only operates on own properties, not inherited properties. + * + * + * @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 own property (default: false) + * @param transform - transform function + * @throws must provide valid options + * @returns function which maps keys from one object to a new object having the same values + * + * @example + * var readFile = require( `@stdlib/fs/read-file` ); + * + * function read( key, value, next ) { + * var opts = { + * 'encoding': 'utf8' + * }; + * readFile( value, opts, onFile ); + * + * function onFile( error ) { + * if ( error ) { + * return next( null, key+':unreadable' ); + * } + * next( null, key+':readable' ); + * } + * } + * + * var opts = { + * 'series': true + * }; + * + * // Create a reusable function: + * var mapKeysAsync = factory( opts, read ); + * + * // Create a dictionary of file names: + * var files = { + * 'file1': './beep.js', + * 'file2': './boop.js' + * }; + * + * // Define a callback which handles errors: + * function done( error, out ) { + * if ( error ) { + * throw error; + * } + * console.log( out ); + * } + * + * // Process each file in `files`: + * mapKeysAsync( files, done ); + */ + factory( options: Options, transform: Transform ): FactoryFunction; + + /** + * Returns a function to map keys from one object to a new object having the same values. + * + * ## Notes + * + * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. + * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). + * - Iteration and insertion order are **not** guaranteed. + * - The function only operates on own properties, not inherited properties. + * + * + * @param transform - transform function + * @returns function which maps keys from one object to a new object having the same values + * + * @example + * var readFile = require( `@stdlib/fs/read-file` ); + * + * function read( key, value, next ) { + * var opts = { + * 'encoding': 'utf8' + * }; + * readFile( value, opts, onFile ); + * + * function onFile( error ) { + * if ( error ) { + * return next( null, key+':unreadable' ); + * } + * next( null, key+':readable' ); + * } + * } + * + * // Create a reusable function: + * var mapKeysAsync = factory( read ); + * + * // Create a dictionary of file names: + * var files = { + * 'file1': './beep.js', + * 'file2': './boop.js' + * }; + * + * // Define a callback which handles errors: + * function done( error, out ) { + * if ( error ) { + * throw error; + * } + * console.log( out ); + * } + * + * // Process each file in `files`: + * mapKeysAsync( files, done ); + */ + factory( transform: Transform ): FactoryFunction; +} + +/** +* Maps keys from one object to a new object having the same values. +* +* ## Notes +* +* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. +* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). +* - Iteration and insertion order are **not** guaranteed. +* - The function only operates on own properties, not inherited properties. +* +* +* @param obj - source object +* @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 own property (default: false) +* @param transform - transform function +* @param done - function to invoke upon completion +* @throws must provide valid options +* +* @example +* var readFile = require( `@stdlib/fs/read-file` ); +* +* function read( key, value, next ) { +* var opts = { +* 'encoding': 'utf8' +* }; +* readFile( value, opts, onFile ); +* +* function onFile( error ) { +* if ( error ) { +* return next( null, key+':unreadable' ); +* } +* next( null, key+':readable' ); +* } +* } +* +* // Define a callback which handles errors: +* function done( error, out ) { +* if ( error ) { +* throw error; +* } +* console.log( out ); +* } +* +* // Create a dictionary of file names: +* var files = { +* 'file1': './beep.js', +* 'file2': './boop.js' +* }; +* +* var opts = { +* 'series': true +* }; +* +* // Process each file in `files`: +* mapKeysAsync( files, opts, read, done ); +*/ +declare var mapKeysAsync: MapKeysAsync; + + +// EXPORTS // + +export = mapKeysAsync; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..403509e --- /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/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import i 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 s 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";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@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 f=i,m=o,c=s.isPrimitive,d=u.isPrimitive,p=r;var h=function(e,t){return f(t)?(m(t,"thisArg")&&(e.thisArg=t.thisArg),m(t,"series")&&(e.series=t.series,!c(e.series))?new TypeError(p("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(p("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(p("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 b(){throw new Error("clearTimeout has not been defined")}var j=v,w=b;function y(e){if(j===setTimeout)return setTimeout(e,0);if((j===v||!j)&&setTimeout)return j=setTimeout,setTimeout(e,0);try{return j(e,0)}catch(t){try{return j.call(null,e,0)}catch(t){return j.call(this,e,0)}}}"function"==typeof g.setTimeout&&(j=setTimeout),"function"==typeof g.clearTimeout&&(w=clearTimeout);var T,x=[],E=!1,O=-1;function A(){E&&T&&(E=!1,T.length?x=T.concat(x):O=-1,x.length&&N())}function N(){if(!E){var e=y(A);E=!0;for(var t=x.length;t;){for(T=x,x=[];++O1)for(var r=1;r %s: %s",t,JSON.stringify(n)),m[t]=n,p()}}i=s[f+=1],n=e[i],G("%s: %s",i,JSON.stringify(n)),2===r.length?r.call(t.thisArg,i,o):3===r.length?r.call(t.thisArg,i,n,o):r.call(t.thisArg,i,n,e,o)}function p(e){return e?(G("Encountered an error: %s",e.message),n(e)):(G("Processed %d of %d properties.",o+=1,a),f1){if(n=Q(r,e))throw n;i=t}else i=e;if(!H(i))throw new TypeError(I("invalid argument. Last argument must be a function. Value: `%s`.",i));return r.series?r.limit=1:r.limit||(r.limit=K),o;function o(e,t){if("object"!=typeof e||null===e)throw new TypeError(I("invalid argument. First argument must be an object. Value: `%s`.",e));if(!H(t))throw new TypeError(I("invalid argument. Last argument must be a function. Value: `%s`.",t));return R(e,r,i,(function(e,r){if(e)return t(e);t(null,r)}))}},W=U;var X=function(e,t,r,n){if(arguments.length<4)return W(t)(e,r);W(t,r)(e,n)},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..b359780 --- /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/map_keys.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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar mapKeysAsync = require( './map_keys.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\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","objectKeys","debug","logger","isFunction","PINF","validate","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory_1","transform","err","f","arguments","mapKeysAsync","factory","lib"],"mappings":";;ijCAsBA,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,iBCevBC,EAAapB,EAKbqB,oCAAQC,CAAQ,0BAoIpB,IC1IIC,EAAazB,EACbQ,EAASN,EACTwB,EAAOtB,EACPuB,EAAWpB,EACXS,EDyBJ,SAAgBY,EAAKjB,EAAMkB,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOX,EAAYM,GACnBQ,EAAMH,EAAKO,OACXjB,EAAO,qBAAsBa,GAE7BE,EAAM,GACO,IAARF,EAEJ,OADAb,EAAO,kCACAO,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMzB,EAAKK,MACToB,EAEAzB,EAAKK,MAEZO,EAAO,wBAAyBY,GAChCZ,EAAO,0BAA2BM,EAAIW,QAEtCT,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdtB,EAAO,6BAA8BoB,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,KA/BDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbpB,EAAO,SAAUoB,EAAKI,KAAKC,UAAWN,IAElB,IAAfb,EAAIW,OACRX,EAAIoB,KAAMtC,EAAKE,QAAS8B,EAAKC,GACH,IAAff,EAAIW,OACfX,EAAIoB,KAAMtC,EAAKE,QAAS8B,EAAKD,EAAOE,GAEpCf,EAAIoB,KAAMtC,EAAKE,QAAS8B,EAAKD,EAAOd,EAAKgB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJtB,EAAO,2BAA4BsB,EAAMK,SAClCpB,EAAMe,KAGdtB,EAAO,iCADPS,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACdb,EAAO,kCACAO,EAAM,KAAMQ,SAFpB,KCOF,IAAAa,EAhEA,SAAkBvC,EAASwC,GAC1B,IAAIzC,EACA0C,EACAC,EAGJ,GADA3C,EAAO,GACF4C,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAM1B,EAAUhB,EAAMC,GAErB,MAAMyC,EAEPC,EAAIF,OAEJE,EAAI1C,EAEL,IAAMa,EAAY6B,GACjB,MAAM,IAAIvC,UAAWP,EAAQ,mEAAoE8C,IAOlG,OALK3C,EAAKG,OACTH,EAAKK,MAAQ,EACDL,EAAKK,QACjBL,EAAKK,MAAQU,GAEP8B,EAYP,SAASA,EAAc5B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIb,UAAWP,EAAQ,mEAAoEoB,IAElG,IAAMH,EAAYK,GACjB,MAAM,IAAIf,UAAWP,EAAQ,mEAAoEsB,IAElG,OAAOd,EAAOY,EAAKjB,EAAM2C,GAUzB,SAAeT,EAAOP,GACrB,GAAKO,EACJ,OAAOf,EAAMe,GAEdf,EAAM,KAAMQ,QC/HXmB,EAAUzD,EA8Ed,IChCAwD,EDsBA,SAAuB5B,EAAKhB,EAASwC,EAAWtB,GAC/C,GAAKyB,UAAUf,OAAS,EACvB,OAAOiB,EAAS7C,EAAT6C,CAAoB7B,EAAKwB,GAEjCK,EAAS7C,EAASwC,EAAlBK,CAA+B7B,EAAKE,ICzBrC2B,EAAArD,EAFAJ,EAOAwD,EAAA,UAAAC,GAKA,IAAAC,EAAAF"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4a1509b --- /dev/null +++ b/package.json @@ -0,0 +1,44 @@ +{ + "name": "@stdlib/utils-async-map-keys", + "version": "0.0.0", + "description": "Map keys from one object to a new object having the same values.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/utils-async-map-keys.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "asynchronous", + "async", + "map", + "transform", + "create", + "copy", + "cp", + "clone", + "extract", + "property", + "keys", + "values", + "object", + "array", + "obj" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b8913b0 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 312f9d55634766b1a27f6181840f95eb9e12efdd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 23:11:33 +0000 Subject: [PATCH 002/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From a21c7ab89c09d7b7a2f194100ea84ec91df5590d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:32:34 +0000 Subject: [PATCH 003/132] Remove files --- index.d.ts | 436 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3130 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 403509e..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/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import i 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 s 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";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@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 f=i,m=o,c=s.isPrimitive,d=u.isPrimitive,p=r;var h=function(e,t){return f(t)?(m(t,"thisArg")&&(e.thisArg=t.thisArg),m(t,"series")&&(e.series=t.series,!c(e.series))?new TypeError(p("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(p("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(p("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 b(){throw new Error("clearTimeout has not been defined")}var j=v,w=b;function y(e){if(j===setTimeout)return setTimeout(e,0);if((j===v||!j)&&setTimeout)return j=setTimeout,setTimeout(e,0);try{return j(e,0)}catch(t){try{return j.call(null,e,0)}catch(t){return j.call(this,e,0)}}}"function"==typeof g.setTimeout&&(j=setTimeout),"function"==typeof g.clearTimeout&&(w=clearTimeout);var T,x=[],E=!1,O=-1;function A(){E&&T&&(E=!1,T.length?x=T.concat(x):O=-1,x.length&&N())}function N(){if(!E){var e=y(A);E=!0;for(var t=x.length;t;){for(T=x,x=[];++O1)for(var r=1;r %s: %s",t,JSON.stringify(n)),m[t]=n,p()}}i=s[f+=1],n=e[i],G("%s: %s",i,JSON.stringify(n)),2===r.length?r.call(t.thisArg,i,o):3===r.length?r.call(t.thisArg,i,n,o):r.call(t.thisArg,i,n,e,o)}function p(e){return e?(G("Encountered an error: %s",e.message),n(e)):(G("Processed %d of %d properties.",o+=1,a),f1){if(n=Q(r,e))throw n;i=t}else i=e;if(!H(i))throw new TypeError(I("invalid argument. Last argument must be a function. Value: `%s`.",i));return r.series?r.limit=1:r.limit||(r.limit=K),o;function o(e,t){if("object"!=typeof e||null===e)throw new TypeError(I("invalid argument. First argument must be an object. Value: `%s`.",e));if(!H(t))throw new TypeError(I("invalid argument. Last argument must be a function. Value: `%s`.",t));return R(e,r,i,(function(e,r){if(e)return t(e);t(null,r)}))}},W=U;var X=function(e,t,r,n){if(arguments.length<4)return W(t)(e,r);W(t,r)(e,n)},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 b359780..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/map_keys.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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar mapKeysAsync = require( './map_keys.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\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","objectKeys","debug","logger","isFunction","PINF","validate","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory_1","transform","err","f","arguments","mapKeysAsync","factory","lib"],"mappings":";;ijCAsBA,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,iBCevBC,EAAapB,EAKbqB,oCAAQC,CAAQ,0BAoIpB,IC1IIC,EAAazB,EACbQ,EAASN,EACTwB,EAAOtB,EACPuB,EAAWpB,EACXS,EDyBJ,SAAgBY,EAAKjB,EAAMkB,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOX,EAAYM,GACnBQ,EAAMH,EAAKO,OACXjB,EAAO,qBAAsBa,GAE7BE,EAAM,GACO,IAARF,EAEJ,OADAb,EAAO,kCACAO,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMzB,EAAKK,MACToB,EAEAzB,EAAKK,MAEZO,EAAO,wBAAyBY,GAChCZ,EAAO,0BAA2BM,EAAIW,QAEtCT,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdtB,EAAO,6BAA8BoB,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,KA/BDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbpB,EAAO,SAAUoB,EAAKI,KAAKC,UAAWN,IAElB,IAAfb,EAAIW,OACRX,EAAIoB,KAAMtC,EAAKE,QAAS8B,EAAKC,GACH,IAAff,EAAIW,OACfX,EAAIoB,KAAMtC,EAAKE,QAAS8B,EAAKD,EAAOE,GAEpCf,EAAIoB,KAAMtC,EAAKE,QAAS8B,EAAKD,EAAOd,EAAKgB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJtB,EAAO,2BAA4BsB,EAAMK,SAClCpB,EAAMe,KAGdtB,EAAO,iCADPS,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACdb,EAAO,kCACAO,EAAM,KAAMQ,SAFpB,KCOF,IAAAa,EAhEA,SAAkBvC,EAASwC,GAC1B,IAAIzC,EACA0C,EACAC,EAGJ,GADA3C,EAAO,GACF4C,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAM1B,EAAUhB,EAAMC,GAErB,MAAMyC,EAEPC,EAAIF,OAEJE,EAAI1C,EAEL,IAAMa,EAAY6B,GACjB,MAAM,IAAIvC,UAAWP,EAAQ,mEAAoE8C,IAOlG,OALK3C,EAAKG,OACTH,EAAKK,MAAQ,EACDL,EAAKK,QACjBL,EAAKK,MAAQU,GAEP8B,EAYP,SAASA,EAAc5B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIb,UAAWP,EAAQ,mEAAoEoB,IAElG,IAAMH,EAAYK,GACjB,MAAM,IAAIf,UAAWP,EAAQ,mEAAoEsB,IAElG,OAAOd,EAAOY,EAAKjB,EAAM2C,GAUzB,SAAeT,EAAOP,GACrB,GAAKO,EACJ,OAAOf,EAAMe,GAEdf,EAAM,KAAMQ,QC/HXmB,EAAUzD,EA8Ed,IChCAwD,EDsBA,SAAuB5B,EAAKhB,EAASwC,EAAWtB,GAC/C,GAAKyB,UAAUf,OAAS,EACvB,OAAOiB,EAAS7C,EAAT6C,CAAoB7B,EAAKwB,GAEjCK,EAAS7C,EAASwC,EAAlBK,CAA+B7B,EAAKE,ICzBrC2B,EAAArD,EAFAJ,EAOAwD,EAAA,UAAAC,GAKA,IAAAC,EAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b8913b0..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a1a61dd3d37e9aefec406b73761f9a7e24b7fe3e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:33:21 +0000 Subject: [PATCH 004/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 -- branches.md | 53 - docs/repl.txt | 187 -- docs/types/test.ts | 166 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 -- lib/index.js | 80 - lib/limit.js | 161 -- lib/map_keys.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1124 --------- test/test.js | 38 - test/test.map_keys.js | 1039 -------- test/test.validate.js | 181 -- 44 files changed, 2718 insertions(+), 6569 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 (100%) 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/map_keys.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.map_keys.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 80727fd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:09:28.848Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..37f76e5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u 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..7b7c452 --- /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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;+0BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 16bfccf..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var mapKeysAsync = require( './map_keys.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( mapKeysAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/map_keys.js b/lib/map_keys.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/map_keys.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..1f8acc5 --- /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 7a9230e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.map_keys.js b/test/test.map_keys.js deleted file mode 100644 index 115b89b..0000000 --- a/test/test.map_keys.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib/map_keys.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 b173482e45b0235770da722e7adbedaee23a8018 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:45:02 +0000 Subject: [PATCH 005/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From 7d5b316c8bf3b4f3915da096969d6ec7fcca80db Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 11:55:24 +0000 Subject: [PATCH 006/132] Remove files --- index.d.ts | 436 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3130 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 37f76e5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b7c452..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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;+0BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1f8acc5..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 63a138ea0d29cbe313d8541d652308c96dfac26d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 11:56:15 +0000 Subject: [PATCH 007/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 -- branches.md | 53 - docs/repl.txt | 187 -- docs/types/test.ts | 166 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 -- lib/index.js | 80 - lib/limit.js | 161 -- lib/map_keys.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1124 --------- test/test.js | 38 - test/test.map_keys.js | 1039 -------- test/test.validate.js | 181 -- 44 files changed, 2718 insertions(+), 6569 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 (100%) 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/map_keys.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.map_keys.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 cd15ed7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:12:59.013Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..37f76e5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u 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..7b7c452 --- /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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;+0BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 16bfccf..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var mapKeysAsync = require( './map_keys.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( mapKeysAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/map_keys.js b/lib/map_keys.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/map_keys.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..e45e041 --- /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 7a9230e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.map_keys.js b/test/test.map_keys.js deleted file mode 100644 index 115b89b..0000000 --- a/test/test.map_keys.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib/map_keys.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 e2a88603c92202db7d39ff40349fad036fd3f7cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 12:57:51 +0000 Subject: [PATCH 008/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From ad6319ad415445b8196f57fb67241d3561a93286 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 13:25:34 +0000 Subject: [PATCH 009/132] Remove files --- index.d.ts | 436 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3130 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 37f76e5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b7c452..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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;+0BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e45e041..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 06773df34a9f18686d66256e92c6ca24ca46e5d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 13:26:27 +0000 Subject: [PATCH 010/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 -- branches.md | 53 - docs/repl.txt | 187 -- docs/types/test.ts | 166 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 -- lib/index.js | 80 - lib/limit.js | 161 -- lib/map_keys.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1124 --------- test/test.js | 38 - test/test.map_keys.js | 1039 -------- test/test.validate.js | 181 -- 43 files changed, 2718 insertions(+), 6534 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 (100%) 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/map_keys.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.map_keys.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 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..37f76e5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u 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..7b7c452 --- /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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;+0BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 16bfccf..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var mapKeysAsync = require( './map_keys.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( mapKeysAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/map_keys.js b/lib/map_keys.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/map_keys.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..e75f78f --- /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 7a9230e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.map_keys.js b/test/test.map_keys.js deleted file mode 100644 index 115b89b..0000000 --- a/test/test.map_keys.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib/map_keys.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 7a3b3d19cbf393a85cf98ec7d346bfe0db0b9686 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 15:25:27 +0000 Subject: [PATCH 011/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From 6d96b9dcf9b84f3f8b39134b93286be0dcc0d3b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 15:25:53 +0000 Subject: [PATCH 012/132] Remove files --- index.d.ts | 436 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3130 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 37f76e5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b7c452..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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;+0BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e75f78f..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From fd883e377ec99deea3f4abbd37473a48953c4fba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 15:26:42 +0000 Subject: [PATCH 013/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 -- branches.md | 53 - docs/repl.txt | 187 -- docs/types/test.ts | 166 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 -- lib/index.js | 80 - lib/limit.js | 161 -- lib/map_keys.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1124 --------- test/test.js | 38 - test/test.map_keys.js | 1039 -------- test/test.validate.js | 181 -- 44 files changed, 2718 insertions(+), 6535 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 (100%) 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/map_keys.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.map_keys.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 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..37f76e5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u 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..7b7c452 --- /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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;+0BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 16bfccf..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var mapKeysAsync = require( './map_keys.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( mapKeysAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/map_keys.js b/lib/map_keys.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/map_keys.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..afeb1d8 --- /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 7a9230e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.map_keys.js b/test/test.map_keys.js deleted file mode 100644 index 115b89b..0000000 --- a/test/test.map_keys.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib/map_keys.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 52a1a1f6daef3b63cb9ed6d496c98d9af14b6565 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:50:41 +0000 Subject: [PATCH 014/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From 26532981f73b171b834e97eaddcd146d95ae4ee3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:12:46 +0000 Subject: [PATCH 015/132] Remove files --- index.d.ts | 436 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3130 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 37f76e5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7b7c452..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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;+0BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index afeb1d8..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ec53a9c92775309c6150382af1c1a70bc60af97f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:13:36 +0000 Subject: [PATCH 016/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 -- branches.md | 53 - docs/repl.txt | 187 -- docs/types/test.ts | 166 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 -- lib/index.js | 80 - lib/limit.js | 161 -- lib/map_keys.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1124 --------- test/test.js | 38 - test/test.map_keys.js | 1039 -------- test/test.validate.js | 181 -- 44 files changed, 2718 insertions(+), 6608 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 (100%) 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/map_keys.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.map_keys.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 45b51c0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:16:08.355Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cbe3bec --- /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 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@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u 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..6c16d6a --- /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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;s1BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 16bfccf..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var mapKeysAsync = require( './map_keys.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( mapKeysAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/map_keys.js b/lib/map_keys.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/map_keys.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..2c16547 --- /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 7a9230e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.map_keys.js b/test/test.map_keys.js deleted file mode 100644 index 115b89b..0000000 --- a/test/test.map_keys.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib/map_keys.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 04e98e3716f28c05a420cb2d041f4d197b111334 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:40:44 +0000 Subject: [PATCH 017/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From 9c1d5bf7910bb2e2d10d084497ffa1a3e183ba57 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:53:33 +0000 Subject: [PATCH 018/132] Remove files --- index.d.ts | 436 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3130 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cbe3bec..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 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@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6c16d6a..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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;s1BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2c16547..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From fbb67692956a43601d054e96885e5426ddc85001 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:54:16 +0000 Subject: [PATCH 019/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 -- branches.md | 53 - docs/repl.txt | 187 -- docs/types/test.ts | 166 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 -- lib/index.js | 80 - lib/limit.js | 161 -- lib/map_keys.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1124 --------- test/test.js | 38 - test/test.map_keys.js | 1039 -------- test/test.validate.js | 181 -- 44 files changed, 2718 insertions(+), 6624 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 (100%) 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/map_keys.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.map_keys.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 224301d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:14:05.785Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cbe3bec --- /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 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@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u 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..6c16d6a --- /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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;s1BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 16bfccf..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var mapKeysAsync = require( './map_keys.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( mapKeysAsync, 'factory', factory ); - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/limit.js b/lib/limit.js deleted file mode 100644 index 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/map_keys.js b/lib/map_keys.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/map_keys.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..b032d51 --- /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 7a9230e..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = factory( {}, next ); - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.map_keys.js b/test/test.map_keys.js deleted file mode 100644 index 115b89b..0000000 --- a/test/test.map_keys.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib/map_keys.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - undefined - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 a9638fac7b4c5b656999ad14d3ef6ed67b48abf5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 17 Sep 2022 19:33:52 +0000 Subject: [PATCH 020/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From af8498db591a51fd93782084fb163b53fe92fdfa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 17 Sep 2022 19:45:19 +0000 Subject: [PATCH 021/132] Remove files --- index.d.ts | 436 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3130 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cbe3bec..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 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@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6c16d6a..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/map_keys.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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport mapKeysAsync from './map_keys.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( mapKeysAsync, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n"],"names":["validate","opts","options","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","debug","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly"],"mappings":";;s1BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAD,EAAA,UAAAP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b032d51..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4556d357c5a06f4b609681e8aded14cb89610c5c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 17 Sep 2022 19:46:04 +0000 Subject: [PATCH 022/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 -- branches.md | 53 - docs/repl.txt | 187 -- docs/types/test.ts | 166 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 -- lib/index.js | 80 - lib/limit.js | 161 -- lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1124 --------- test/test.js | 38 - test/test.main.js | 1039 -------- test/test.validate.js | 181 -- 43 files changed, 2718 insertions(+), 6623 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 (100%) 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 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cbe3bec --- /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 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@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u 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..2e4c07c --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;s1BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..e47f65a --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 958b6ecde8bf4ddcaf3da0b9b5c31f652b26cf22 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:44:18 +0000 Subject: [PATCH 023/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From 47df88ca589598f50735afba1bc642cbad3a1530 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Oct 2022 00:44:31 +0000 Subject: [PATCH 024/132] Remove files --- index.d.ts | 436 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3130 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cbe3bec..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 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@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2e4c07c..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;s1BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e47f65a..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 9e499b5b6bf7f934ad611cb18b6535006bed4c62 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Oct 2022 00:45:22 +0000 Subject: [PATCH 025/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 -- branches.md | 53 - docs/repl.txt | 187 -- docs/types/test.ts | 166 -- examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 -- lib/index.js | 80 - lib/limit.js | 161 -- lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 1124 --------- test/test.js | 38 - test/test.main.js | 1039 -------- test/test.validate.js | 181 -- 44 files changed, 2718 insertions(+), 6624 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 (100%) 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 a814181..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:40:11.336Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cbe3bec --- /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 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@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u 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..2e4c07c --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;s1BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..b49a9db --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 4205a752bb11eadf6f08c94c66a9b0502ec76f35 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 04:21:11 +0000 Subject: [PATCH 026/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From f7ca0db43865190cd5325fca8e4b86c70184dbcf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:56:25 +0000 Subject: [PATCH 027/132] Remove files --- index.d.ts | 436 -------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3130 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cbe3bec..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 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@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2e4c07c..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;s1BAsDA,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,QC5BrCU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,GACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,KA/BDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,GAgC3C,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,ICzDF,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,GACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,OAEJE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,OC3Df,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,GCpBrC8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b49a9db..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ac6eb17241677bb5ddc64464ee19bb6beb2f2f9d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:57:28 +0000 Subject: [PATCH 028/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 1124 ------ test/test.js | 38 - test/test.main.js | 1039 ------ test/test.validate.js | 181 - 44 files changed, 4073 insertions(+), 6624 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 (100%) 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 26b698a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:27:16.184Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a188a6e --- /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 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.7-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u 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..0e94c2a --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,KC9CIU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,CAAA,EACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,EAIA,CACF,CC9DA,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,CAAA,EACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,CACN,MACEE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..b6d8f39 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 2070655fa72293ce8835e278a4282fa30b387061 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:13:48 +0000 Subject: [PATCH 029/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bf8a690..eebd591 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From 3c681cf71c6e36c980f6d924a47e5734b9a6fe8b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 07:53:23 +0000 Subject: [PATCH 030/132] Remove files --- index.d.ts | 436 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4485 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a188a6e..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 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.7-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function d(i,t){return e(t)?(n(t,"thisArg")&&(i.thisArg=t.thisArg),n(t,"series")&&(i.series=t.series,!o(i.series))?new TypeError(r("0iY30","series",i.series)):n(t,"limit")&&(i.limit=t.limit,!l(i.limit))?new TypeError(r("0iY3b","limit",i.limit)):null):new TypeError(r("0iY2h",t))}var f=()=>{};function h(i,t,r,s){var e,n,o,l,d,h,p,u,j;if(o=m(i),h=o.length,u={},0===h)return s(null,u);for(d=h %s: %s",t,JSON.stringify(s)),u[t]=s,c()}}e=o[p+=1],s=i[e],f("%s: %s",e,JSON.stringify(s)),2===r.length?r.call(t.thisArg,e,n):3===r.length?r.call(t.thisArg,e,s,n):r.call(t.thisArg,e,s,i,n)}function c(i){return i?(f("Encountered an error: %s",i.message),s(i)):(n+=1,p1){if(o=d(n,i))throw o;l=e}else l=i;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=s),m;function m(i,s){if("object"!=typeof i||null===i)throw new TypeError(r("0iY3X",i));if(!t(s))throw new TypeError(r("0iY43",s));return h(i,n,l,(function(i,t){if(i)return s(i);s(null,t)}))}}function u(i,t,r,s){if(arguments.length<4)return p(t)(i,r);p(t,r)(i,s)}i(u,"factory",p);export{u as default,p as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0e94c2a..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' ;\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,KC9CIU,SAuBJ,SAASF,EAAOG,EAAKZ,EAAMa,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OAGXH,EAAM,CAAA,EACO,IAARF,EAEJ,OAAON,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMpB,EAAKS,MACTW,EAEApB,EAAKS,MAGZE,EAAO,0BAA2BE,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdnB,EAAO,6BAA8BiB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACbjB,EAAO,SAAUiB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMlC,EAAKI,QAASwB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJnB,EAAO,2BAA4BmB,EAAMK,SAClCrB,EAAMgB,KAEdd,GAAS,EAEJK,EAAMN,EACHW,IAEHV,IAAUI,EAEPN,EAAM,KAAMQ,QAFpB,EAIA,CACF,CC9DA,SAASc,EAASnC,EAASoC,GAC1B,IAAIrC,EACAsC,EACAC,EAGJ,GADAvC,EAAO,CAAA,EACFwC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMvC,EAAUC,EAAMC,GAErB,MAAMqC,EAEPC,EAAIF,CACN,MACEE,EAAItC,EAEL,IAAMwC,EAAYF,GACjB,MAAM,IAAIhC,UAAWC,EAAQ,QAAS+B,IAOvC,OALKvC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQiC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIL,UAAWC,EAAQ,QAASI,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,OAAOL,EAAOG,EAAKZ,EAAMuC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKX,EAASoC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASnC,EAATmC,CAAoBxB,EAAKyB,GAEjCD,EAASnC,EAASoC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b6d8f39..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4c6b369403e7e3d06e356595c35eca71c6f492c0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 07:54:17 +0000 Subject: [PATCH 031/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 1124 ------ test/test.js | 38 - test/test.main.js | 1039 ------ test/test.validate.js | 181 - 44 files changed, 4073 insertions(+), 6645 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 (100%) 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 96c14a3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:05:48.792Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3a03800 --- /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/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){var t=e.default;if("function"==typeof t){var r=function(){return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..6d72aa7 --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,0WC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebd591..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..fffc64c --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 e73a6cf32e8ad0b053b1c883e1966784e644a12b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 01:55:57 +0000 Subject: [PATCH 032/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 53ab6f3..b626b66 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From 5ac170524dad45973f5ca664dda4ac6c73924fa2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 11:37:06 +0000 Subject: [PATCH 033/132] Remove files --- index.d.ts | 436 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4485 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3a03800..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/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){var t=e.default;if("function"==typeof t){var r=function(){return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 6d72aa7..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys' ;\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file' ;\n* import mapKeysAsync from '@stdlib/utils-async-map-keys' ;\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,0WC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fffc64c..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From e50d314ee0b55851c29d6fbf80952d59a996a8dc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 11:38:06 +0000 Subject: [PATCH 034/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 1124 ------ test/test.js | 38 - test/test.main.js | 1039 ------ test/test.validate.js | 181 - 44 files changed, 4073 insertions(+), 6650 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 (100%) 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 92ed579..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T01:55:13.557Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3a03800 --- /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/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){var t=e.default;if("function"==typeof t){var r=function(){return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..27c45fc --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,0WC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index b626b66..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..28e725a --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 1624602a9e0da34aba44b60aed42155516db02b8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 02:58:16 +0000 Subject: [PATCH 035/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bebe5a4..f283919 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From 943b3d3d87c9bb30fba3a8d276d5eed5b5b31627 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 12:36:11 +0000 Subject: [PATCH 036/132] Remove files --- index.d.ts | 436 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4485 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3a03800..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/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){var t=e.default;if("function"==typeof t){var r=function(){return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 27c45fc..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,0WC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 28e725a..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 8ca00f6a265a35b60882cdfb64a6dbe0892b30c8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 12:37:05 +0000 Subject: [PATCH 037/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 1124 ------ test/test.js | 38 - test/test.main.js | 1039 ------ test/test.validate.js | 181 - 44 files changed, 4073 insertions(+), 6661 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 (100%) 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 353db8f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T01:17:43.151Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c9cc542 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){var t=e.default;if("function"==typeof t){var r=function(){return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..27c45fc --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,0WC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f283919..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..5a1cfd3 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 33201d78f040183ef11a0e0704368e414f43ee01 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:52:50 +0000 Subject: [PATCH 038/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index bebe5a4..f283919 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.x", "@stdlib/utils-keys": "^0.0.x", "debug": "^2.6.9" From 233db92daa708e1c78fc96d0c077a0d2ec3bbc63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 15:08:48 +0000 Subject: [PATCH 039/132] Remove files --- index.d.ts | 436 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4485 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c9cc542..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){var t=e.default;if("function"==typeof t){var r=function(){return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 27c45fc..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,0WC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5a1cfd3..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 138994d3750daae39e60607afeb2d8eedaed3f15 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 15:09:41 +0000 Subject: [PATCH 040/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 44 files changed, 6206 insertions(+), 6661 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 (100%) 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 74a8ad7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T01:42:55.373Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0248655..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/map-keys" -click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4ac40c3 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b25a694 --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;+0BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f283919..f770654 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.x", - "@stdlib/utils-keys": "^0.0.x", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/fs-read-file": "^0.0.x", - "@stdlib/random-base-randu": "^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..9ed0b87 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 c2f4de509a1e5f027f175adf6fb7e991e5f7545d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 06:43:24 +0000 Subject: [PATCH 041/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 3c33de8..7d715d5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.7", "@stdlib/utils-keys": "^0.0.7", "debug": "^2.6.9" From 405a14f302dff367d8f1eefaed9d6bfe3fb41e68 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 15:53:44 +0000 Subject: [PATCH 042/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4ac40c3..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index b25a694..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;+0BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9ed0b87..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6045bba4dea15c7bf8b642aa526c5465e19f9396 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 15:54:29 +0000 Subject: [PATCH 043/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 44 files changed, 6206 insertions(+), 6796 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 (100%) 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 4910510..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T04:19:53.881Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cfca4f5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fb2f77b --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d715d5..4cfecf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/utils-keys": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/random-base-randu": "^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..827ea13 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 b2f2f204d47dbb3843f509fc7aa5d45ad6ac4f00 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 07:16:55 +0000 Subject: [PATCH 044/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 3c33de8..7d715d5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.7", "@stdlib/utils-keys": "^0.0.7", "debug": "^2.6.9" From 6624b6496ffb8d5317e22f090e9360e0fbdb569d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 14:53:29 +0000 Subject: [PATCH 045/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cfca4f5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fb2f77b..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 827ea13..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 76c119e299de08d25e8629eff605bc665e336ae5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 14:54:50 +0000 Subject: [PATCH 046/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 44 files changed, 6206 insertions(+), 6802 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 (100%) 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 e1c3f9f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T04:58:39.186Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cfca4f5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fb2f77b --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d715d5..4cfecf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/utils-keys": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/random-base-randu": "^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..9985d74 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 eedfb3b741e049de76835a27b141256c24bb78ee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 07:00:21 +0000 Subject: [PATCH 047/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 3c33de8..7d715d5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.7", "@stdlib/utils-keys": "^0.0.7", "debug": "^2.6.9" From b114ff833afcec3306b5a3b22e31429c4efbbb62 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 14:31:49 +0000 Subject: [PATCH 048/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cfca4f5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fb2f77b..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9985d74..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 50d07911e7a6b797e67e4aa9faefe97ec86d5458 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 14:32:51 +0000 Subject: [PATCH 049/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 44 files changed, 6206 insertions(+), 6802 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 (100%) 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 6ff2f67..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T04:41:37.902Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cfca4f5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fb2f77b --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d715d5..4cfecf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/utils-keys": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/random-base-randu": "^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..166f46a --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 d879fc18d8376f658f976b219017be2ee7a81429 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 06:45:16 +0000 Subject: [PATCH 050/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 3c33de8..7d715d5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.7", "@stdlib/utils-keys": "^0.0.7", "debug": "^2.6.9" From 49cc47feb14e82fbba5673046a8c11111f26927f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 14:51:30 +0000 Subject: [PATCH 051/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cfca4f5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fb2f77b..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 166f46a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ab6d213bf0e59f2cbb3210d71796106e8fcb7a53 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 14:52:28 +0000 Subject: [PATCH 052/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 44 files changed, 6206 insertions(+), 6802 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 (100%) 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 1dd0836..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T04:19:02.894Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cfca4f5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fb2f77b --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d715d5..4cfecf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/utils-keys": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/random-base-randu": "^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..cf743e2 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 0145d405355c1998a6b51da00a5367a1ca029dd9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 06:40:38 +0000 Subject: [PATCH 053/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 3c33de8..7d715d5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.7", "@stdlib/utils-keys": "^0.0.7", "debug": "^2.6.9" From bfd041d8dddde1390d15c2346f3f2479ecd983fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 15:14:28 +0000 Subject: [PATCH 054/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cfca4f5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fb2f77b..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cf743e2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b5e722810fd87fbd85082a4dcbdd3f26ad74e3dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 15:15:22 +0000 Subject: [PATCH 055/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 44 files changed, 6206 insertions(+), 6802 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 (100%) 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 9bc0ad4..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T04:18:08.859Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cfca4f5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fb2f77b --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d715d5..4cfecf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/utils-keys": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/random-base-randu": "^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..cf72a06 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 052eca1a4d91364a5f31d71da3df813f9b24f018 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 07:19:27 +0000 Subject: [PATCH 056/132] 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 ed753a8..2f31aaa 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -107,7 +107,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -128,10 +128,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 3c33de8..7d715d5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.7", "@stdlib/utils-keys": "^0.0.7", "debug": "^2.6.9" From 1963e719bdbf754accbe009c605d7b2df1bc1917 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 15:49:32 +0000 Subject: [PATCH 057/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cfca4f5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fb2f77b..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cf72a06..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0329fcc06f7d890c8a710e58446a2516136449e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 15:50:30 +0000 Subject: [PATCH 058/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 158 - lib/index.js | 80 - lib/limit.js | 161 - lib/main.js | 101 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 44 files changed, 6206 insertions(+), 6802 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 (100%) 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 3cbee2a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T04:46:18.508Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cfca4f5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..fb2f77b --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 2f31aaa..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,158 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 9a2987d..0000000 --- a/lib/limit.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 35675a5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d715d5..4cfecf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/utils-keys": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/random-base-randu": "^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..7753994 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 76071a8ec6dce2b8d2ec4388815d19805d9aadfe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 2 Aug 2023 16:47:29 +0000 Subject: [PATCH 059/132] 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 5fea796..3275463 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '0iY43', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '0iY3X', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '0iY43', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..7fe5596 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( '0iY2h', 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( '0iY30', '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( '0iY3b', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 3c33de8..7d715d5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.0.7", "@stdlib/utils-keys": "^0.0.7", "debug": "^2.6.9" From d67bbd9228588b12fe565ec2aa2a93bb8d965685 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 2 Aug 2023 16:52:20 +0000 Subject: [PATCH 060/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cfca4f5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index fb2f77b..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAuBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCrBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7753994..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d30355f3667a7ad38782c6751f552249098e41ec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 2 Aug 2023 16:54:15 +0000 Subject: [PATCH 061/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 43 files changed, 6206 insertions(+), 6798 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 (100%) 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 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -401,7 +400,7 @@ mapKeysAsync( files, 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]. @@ -465,9 +464,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cfca4f5 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0bdae34 --- /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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 3275463..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '0iY43', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '0iY3X', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '0iY43', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 7fe5596..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 own property -* @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( '0iY2h', 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( '0iY30', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '0iY3b', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d715d5..4cfecf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.8", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.0.7", - "@stdlib/utils-keys": "^0.0.7", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/fs-read-file": "^0.0.8", - "@stdlib/random-base-randu": "^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..7754f59 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 790a1ca1b24c2eac2b36e91fa793941a30d441a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 21:24:00 +0000 Subject: [PATCH 062/132] 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 5fea796..5ae34e5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q,JV', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L,Gc', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q,JV', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..2a821cc 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( '1RP2V,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( '1RP2o,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( '1RP3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index da01a41..239e79c 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.1.0", "@stdlib/utils-keys": "^0.1.0", "debug": "^2.6.9" From 5a9493ce4109c654b8e15a3c1a2b0ffe4b38ae55 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 21:33:35 +0000 Subject: [PATCH 063/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 284be58..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cfca4f5..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("0iY30","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("0iY3b","limit",e.limit)):null):new TypeError(r("0iY2h",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("0iY43",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("0iY3X",e));if(!t(i))throw new TypeError(r("0iY43",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0bdae34..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 own property\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( '0iY2h', 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( '0iY30', '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( '0iY3b', '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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '0iY43', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '0iY3X', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '0iY43', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;61BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,QAASgC,IAOvC,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,QAASK,IAEvC,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7754f59..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 720d917cc3c125391eecd82b2a363709bcb19232 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 21:35:27 +0000 Subject: [PATCH 064/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 47 files changed, 6206 insertions(+), 6839 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 (100%) 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 4552d44..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/map-keys) 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 5ebcd84..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/map-keys) 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 5eacb43..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: '21 9 * * 0' - - # 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 + + ```
@@ -412,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -476,9 +475,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..59c314d --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..450ff35 --- /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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;u4BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 5ae34e5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q,JV', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L,Gc', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q,JV', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2a821cc..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 own property -* @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( '1RP2V,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( '1RP2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 239e79c..175e5be 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.1.0", - "@stdlib/utils-keys": "^0.1.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/fs-read-file": "^0.1.0", - "@stdlib/random-base-randu": "^0.0.8", - "@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..dfa22f2 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 c2984833d9012e9f9b67f2674c4cbe23023297d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 21:41:47 +0000 Subject: [PATCH 065/132] 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 2f6977a..bbd279c 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@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-map-keys@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.1.0-esm/index.mjs'; ``` #### mapKeysAsync( obj, \[options,] transform, done ) @@ -340,7 +340,7 @@ The function accepts the same `options` as `mapKeysAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.1.0-esm/index.mjs'; var files = { 'file1': resolve( __dirname, 'package.json' ), From 4024975df3eb9e8a678d7e181da08788b48d0ee1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 21:41:48 +0000 Subject: [PATCH 066/132] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bbd279c..87f8c1c 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@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-map-keys/tags). For example, + ```javascript import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.1.0-esm/index.mjs'; ``` @@ -58,7 +63,7 @@ import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map- You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.1.0-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; ``` #### mapKeysAsync( obj, \[options,] transform, done ) @@ -340,7 +345,7 @@ The function accepts the same `options` as `mapKeysAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.1.0-esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; var files = { 'file1': resolve( __dirname, 'package.json' ), From 2dcdcc5a254a1eb287cbfb79a54a9a675d649f54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 08:36:28 +0000 Subject: [PATCH 067/132] 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 5fea796..5ae34e5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q,JV', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L,Gc', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q,JV', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..2a821cc 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( '1RP2V,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( '1RP2o,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( '1RP3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4fba113..4cd9fce 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.1.0", "@stdlib/utils-keys": "^0.1.0", "debug": "^2.6.9" From cfbbd548b0e130a9fdf771ce5a1dd436f8feef03 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 14:35:44 +0000 Subject: [PATCH 068/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 dc8085c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 59c314d..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 450ff35..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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;u4BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index dfa22f2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 355206c0648503df0d144700accd8931cef49180 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 14:38:27 +0000 Subject: [PATCH 069/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 38 - test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 49 files changed, 6206 insertions(+), 6936 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 (100%) 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 b74d9ab..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T03:06:30.614Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 bc2ec00..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: '21 9 * * 0' - - # 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 + + ```
@@ -412,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -476,9 +475,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bf24e39 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7d994da --- /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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;84BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 5ae34e5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q,JV', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L,Gc', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q,JV', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2a821cc..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 own property -* @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( '1RP2V,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( '1RP2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4cd9fce..175e5be 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.1.0", - "@stdlib/utils-keys": "^0.1.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/fs-read-file": "^0.1.0", - "@stdlib/random-base-randu": "^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..0d297c9 --- /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 59f7113..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 mapKeysAsync = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 776af417dbf68be5c22fe5f8848940167faa9899 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 12:22:55 +0000 Subject: [PATCH 070/132] 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 5fea796..5ae34e5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q,JV', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L,Gc', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q,JV', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..2a821cc 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( '1RP2V,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( '1RP2o,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( '1RP3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4d25742..f6de8ef 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.1.1", "@stdlib/utils-keys": "^0.1.0", "debug": "^2.6.9" From 64d41f4b3c01de1428e1774f1c1ba75406c17e34 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 15:58:00 +0000 Subject: [PATCH 071/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 dc8085c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bf24e39..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7d994da..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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;84BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0d297c9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ad90e36a2d1a1a23f61182358bbd077d5dbd77ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 16:01:06 +0000 Subject: [PATCH 072/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 38 - test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 48 files changed, 6206 insertions(+), 6935 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 (100%) 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 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 bc2ec00..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: '21 9 * * 0' - - # 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 + + ```
@@ -412,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -476,9 +475,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..23c0c09 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i 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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7d994da --- /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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;84BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 5ae34e5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q,JV', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L,Gc', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q,JV', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2a821cc..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 own property -* @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( '1RP2V,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( '1RP2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f6de8ef..175e5be 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-keys": "^0.1.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@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..6559133 --- /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 59f7113..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 mapKeysAsync = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 74aa09405427ecfb6a46806e5eb46ed417fbce54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 08:46:33 +0000 Subject: [PATCH 073/132] 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 5fea796..5ae34e5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q,JV', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L,Gc', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q,JV', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..2a821cc 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( '1RP2V,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( '1RP2o,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( '1RP3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4d25742..f6de8ef 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.1.1", "@stdlib/utils-keys": "^0.1.0", "debug": "^2.6.9" From df61ac3149b132e5af7166096f7d87770bf0698c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 15:20:27 +0000 Subject: [PATCH 074/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 dc8085c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 23c0c09..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i 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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7d994da..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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;84BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6559133..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f0f53281ea2a1dac7cb9bba790d01593846869ca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 15:23:43 +0000 Subject: [PATCH 075/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 49 files changed, 6206 insertions(+), 6939 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 (100%) 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 668689f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T03:14:08.969Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 bc2ec00..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: '21 9 * * 0' - - # 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 + + ```
@@ -412,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -476,9 +475,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..23c0c09 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i 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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7d994da --- /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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;84BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 5ae34e5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q,JV', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L,Gc', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q,JV', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2a821cc..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 own property -* @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( '1RP2V,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( '1RP2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f6de8ef..175e5be 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-keys": "^0.1.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@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..a3d765f --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 f01091e8e680ee3ef6134ce1496230ba0ddd5d56 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 07:32:32 +0000 Subject: [PATCH 076/132] 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 5fea796..5ae34e5 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q,JV', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L,Gc', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q,JV', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..2a821cc 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( '1RP2V,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( '1RP2o,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( '1RP3P,Fv', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 9ddc05f..94fc13e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.1.1", "@stdlib/utils-keys": "^0.1.0", "debug": "^2.6.9" From 46326086b41111351adba9ca6d18b56a48e3db73 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 02:55:00 +0000 Subject: [PATCH 077/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 dc8085c..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; // tslint-disable-line max-line-length - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; // tslint-disable-line max-line-length - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; // tslint-disable-line max-line-length - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 23c0c09..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i 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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7d994da..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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;84BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a3d765f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f6878cc490309ace581e34492102968fdac52497 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 02:57:12 +0000 Subject: [PATCH 078/132] 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 | 45 +- benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 49 files changed, 6206 insertions(+), 6934 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 (100%) 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 cec1a92..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T03:24:34.714Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 bc2ec00..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: '21 9 * * 0' - - # 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 + + ```
@@ -412,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -476,9 +475,9 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/tree/esm diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 87a1b11..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c461fa5..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..23c0c09 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i 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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..7d994da --- /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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;84BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 5ae34e5..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q,JV', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L,Gc', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q,JV', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 2a821cc..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 own property -* @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( '1RP2V,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( '1RP2o,GE', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P,Fv', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 94fc13e..175e5be 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-keys": "^0.1.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/bench": "^0.2.1", - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@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..a57ab8b --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 59b7bbadcd2939897a84804f5acda65628aa905d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 04:48:00 +0000 Subject: [PATCH 079/132] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d038f48..c54d114 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.1.1", "@stdlib/utils-keys": "^0.1.0", "debug": "^2.6.9" From 217c1ad4d058900ce015f8105c42b975f68c507d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 11:11:55 +0000 Subject: [PATCH 080/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 a051baf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 23c0c09..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import i 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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function f(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o,GE","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P,Fv","limit",e.limit)):null):new TypeError(r("1RP2V,FD",t))}function d(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){if(this instanceof e){var r=[null];r.push.apply(r,arguments);var i=Function.bind.apply(t,r);return new i}return t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var p=d(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function u(e,t,r,i){var s,n,o,l,f,d,u,c,a;if(o=m(e),d=o.length,p("Number of keys: %d",d),c={},0===d)return p("Finished processing an object."),i(null,c);for(f=d %s: %s",t,JSON.stringify(i)),c[t]=i,j()}}s=o[u+=1],i=e[s],p("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(p("Encountered an error: %s",e.message),i(e)):(p("Processed %d of %d properties.",n+=1,d),u1){if(o=f(n,e))throw o;l=s}else l=e;if(!t(l))throw new TypeError(r("1RP3q,JV",l));return n.series?n.limit=1:n.limit||(n.limit=i),m;function m(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L,Gc",e));if(!t(i))throw new TypeError(r("1RP3q,JV",i));return u(e,n,l,(function(e,t){if(e)return i(e);i(null,t)}))}}function a(e,t,r,i){if(arguments.length<4)return c(t)(e,r);c(t,r)(e,i)}e(a,"factory",c);export{a as default,c as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 7d994da..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 own property\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( '1RP2V,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( '1RP2o,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( '1RP3P,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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q,JV', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L,Gc', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q,JV', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;84BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,WAAYgC,IAO1C,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,WAAYK,IAE1C,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,WAAYO,IAE1C,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a57ab8b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6e7b10bdbe6602ca2b3de5b61621df6470a278b3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 11:12:25 +0000 Subject: [PATCH 081/132] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 50 files changed, 6206 insertions(+), 6940 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 (100%) 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 e71aec0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T02:56:58.189Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 238e9c5..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: '21 9 * * 0' - - # 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 + + ```
@@ -412,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -476,9 +475,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 622dce4..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6a65a6c --- /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/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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function u(e,t){return n(t)?(s(t,"thisArg")&&(e.thisArg=t.thisArg),s(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):s(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(i("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function m(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 p=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function d(e,t,i,r){var n,s,o,l,u,m,d,f,c;if(o=a(e),m=o.length,p("Number of keys: %d",m),f={},0===m)return p("Finished processing an object."),r(null,f);for(u=m %s: %s",t,JSON.stringify(r)),f[t]=r,h()}}n=o[d+=1],r=e[n],p("%s: %s",n,JSON.stringify(r)),2===i.length?i.call(t.thisArg,n,s):3===i.length?i.call(t.thisArg,n,r,s):i.call(t.thisArg,n,r,e,s)}function h(e){return e?(p("Encountered an error: %s",e.message),r(e)):(p("Processed %d of %d properties.",s+=1,m),d1){if(o=u(s,e))throw o;l=n}else l=e;if(!t(l))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",l));return s.series?s.limit=1:s.limit||(s.limit=r),a;function a(e,r){if("object"!=typeof e||null===e)throw new TypeError(i("invalid argument. First argument must be an object. Value: `%s`.",e));if(!t(r))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",r));return d(e,s,l,(function(e,t){if(e)return r(e);r(null,t)}))}}function c(e,t,i,r){if(arguments.length<4)return f(t)(e,i);f(t,i)(e,r)}e(c,"factory",f);export{c 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..5ba3992 --- /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 own property\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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;q4BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,mEAAoEgC,IAOlG,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,mEAAoEK,IAElG,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,mEAAoEO,IAElG,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 5fea796..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index ba411d4..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 own property -* @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 c54d114..175e5be 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-keys": "^0.1.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@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..3e5c036 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 5c7702609d57795b7b7eb9ba2f9e596cc140a583 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 05:17:12 +0000 Subject: [PATCH 082/132] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d038f48..c54d114 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.1.1", "@stdlib/utils-keys": "^0.1.0", "debug": "^2.6.9" From eda53c20fbae8a4002ae634e099fb77156d27657 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 10:35:39 +0000 Subject: [PATCH 083/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 a051baf..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( `@stdlib/fs/read-file` ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( `@stdlib/fs/read-file` ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6a65a6c..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/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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function u(e,t){return n(t)?(s(t,"thisArg")&&(e.thisArg=t.thisArg),s(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):s(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(i("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function m(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 p=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function d(e,t,i,r){var n,s,o,l,u,m,d,f,c;if(o=a(e),m=o.length,p("Number of keys: %d",m),f={},0===m)return p("Finished processing an object."),r(null,f);for(u=m %s: %s",t,JSON.stringify(r)),f[t]=r,h()}}n=o[d+=1],r=e[n],p("%s: %s",n,JSON.stringify(r)),2===i.length?i.call(t.thisArg,n,s):3===i.length?i.call(t.thisArg,n,r,s):i.call(t.thisArg,n,r,e,s)}function h(e){return e?(p("Encountered an error: %s",e.message),r(e)):(p("Processed %d of %d properties.",s+=1,m),d1){if(o=u(s,e))throw o;l=n}else l=e;if(!t(l))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",l));return s.series?s.limit=1:s.limit||(s.limit=r),a;function a(e,r){if("object"!=typeof e||null===e)throw new TypeError(i("invalid argument. First argument must be an object. Value: `%s`.",e));if(!t(r))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",r));return d(e,s,l,(function(e,t){if(e)return r(e);r(null,t)}))}}function c(e,t,i,r){if(arguments.length<4)return f(t)(e,i);f(t,i)(e,r)}e(c,"factory",f);export{c as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5ba3992..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 own property\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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;q4BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,mEAAoEgC,IAOlG,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,mEAAoEK,IAElG,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,mEAAoEO,IAElG,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3e5c036..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ffe0d401d67c33f85770547687837a1e99d62cff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 10:36:01 +0000 Subject: [PATCH 084/132] 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 | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 50 files changed, 6206 insertions(+), 6945 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 (100%) 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 ea9117a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T03:33:10.065Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 238e9c5..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6a65a6c --- /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/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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function u(e,t){return n(t)?(s(t,"thisArg")&&(e.thisArg=t.thisArg),s(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):s(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(i("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function m(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 p=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function d(e,t,i,r){var n,s,o,l,u,m,d,f,c;if(o=a(e),m=o.length,p("Number of keys: %d",m),f={},0===m)return p("Finished processing an object."),r(null,f);for(u=m %s: %s",t,JSON.stringify(r)),f[t]=r,h()}}n=o[d+=1],r=e[n],p("%s: %s",n,JSON.stringify(r)),2===i.length?i.call(t.thisArg,n,s):3===i.length?i.call(t.thisArg,n,r,s):i.call(t.thisArg,n,r,e,s)}function h(e){return e?(p("Encountered an error: %s",e.message),r(e)):(p("Processed %d of %d properties.",s+=1,m),d1){if(o=u(s,e))throw o;l=n}else l=e;if(!t(l))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",l));return s.series?s.limit=1:s.limit||(s.limit=r),a;function a(e,r){if("object"!=typeof e||null===e)throw new TypeError(i("invalid argument. First argument must be an object. Value: `%s`.",e));if(!t(r))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",r));return d(e,s,l,(function(e,t){if(e)return r(e);r(null,t)}))}}function c(e,t,i,r){if(arguments.length<4)return f(t)(e,i);f(t,i)(e,r)}e(c,"factory",f);export{c 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..5ba3992 --- /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 own property\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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;q4BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,mEAAoEgC,IAOlG,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,mEAAoEK,IAElG,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,mEAAoEO,IAElG,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 5fea796..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index ba411d4..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 own property -* @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 c54d114..175e5be 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.1.1", - "@stdlib/utils-keys": "^0.1.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@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..8faae76 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 b86ac6e4eb773c7d7ca149cda9b93759baa192cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 09:26:14 +0000 Subject: [PATCH 085/132] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 169a299..8d275f5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.0", "@stdlib/utils-keys": "^0.2.0", "debug": "^2.6.9" From 623c6aeba39068a4b745506cdca7cf9373713913 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 18:15:52 +0000 Subject: [PATCH 086/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6a65a6c..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/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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function u(e,t){return n(t)?(s(t,"thisArg")&&(e.thisArg=t.thisArg),s(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):s(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(i("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function m(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 p=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function d(e,t,i,r){var n,s,o,l,u,m,d,f,c;if(o=a(e),m=o.length,p("Number of keys: %d",m),f={},0===m)return p("Finished processing an object."),r(null,f);for(u=m %s: %s",t,JSON.stringify(r)),f[t]=r,h()}}n=o[d+=1],r=e[n],p("%s: %s",n,JSON.stringify(r)),2===i.length?i.call(t.thisArg,n,s):3===i.length?i.call(t.thisArg,n,r,s):i.call(t.thisArg,n,r,e,s)}function h(e){return e?(p("Encountered an error: %s",e.message),r(e)):(p("Processed %d of %d properties.",s+=1,m),d1){if(o=u(s,e))throw o;l=n}else l=e;if(!t(l))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",l));return s.series?s.limit=1:s.limit||(s.limit=r),a;function a(e,r){if("object"!=typeof e||null===e)throw new TypeError(i("invalid argument. First argument must be an object. Value: `%s`.",e));if(!t(r))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",r));return d(e,s,l,(function(e,t){if(e)return r(e);r(null,t)}))}}function c(e,t,i,r){if(arguments.length<4)return f(t)(e,i);f(t,i)(e,r)}e(c,"factory",f);export{c as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5ba3992..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 own property\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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;q4BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,mEAAoEgC,IAOlG,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,mEAAoEK,IAElG,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,mEAAoEO,IAElG,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8faae76..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3eb4b71fa5b23786d287fd20c5ae4ec5baa94258 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 18:16:58 +0000 Subject: [PATCH 087/132] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 49 files changed, 6206 insertions(+), 6948 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 (100%) 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 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 1b6a2d7..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b9fd740 --- /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/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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function u(e,t){return n(t)?(s(t,"thisArg")&&(e.thisArg=t.thisArg),s(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):s(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(i("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function m(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 p=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function d(e,t,i,r){var n,s,o,l,u,m,d,f,c;if(o=a(e),m=o.length,p("Number of keys: %d",m),f={},0===m)return p("Finished processing an object."),r(null,f);for(u=m %s: %s",t,JSON.stringify(r)),f[t]=r,h()}}n=o[d+=1],r=e[n],p("%s: %s",n,JSON.stringify(r)),2===i.length?i.call(t.thisArg,n,s):3===i.length?i.call(t.thisArg,n,r,s):i.call(t.thisArg,n,r,e,s)}function h(e){return e?(p("Encountered an error: %s",e.message),r(e)):(p("Processed %d of %d properties.",s+=1,m),d1){if(o=u(s,e))throw o;l=n}else l=e;if(!t(l))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",l));return s.series?s.limit=1:s.limit||(s.limit=r),a;function a(e,r){if("object"!=typeof e||null===e)throw new TypeError(i("invalid argument. First argument must be an object. Value: `%s`.",e));if(!t(r))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",r));return d(e,s,l,(function(e,t){if(e)return r(e);r(null,t)}))}}function c(e,t,i,r){if(arguments.length<4)return f(t)(e,i);f(t,i)(e,r)}e(c,"factory",f);export{c 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..5ba3992 --- /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 own property\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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;q4BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,mEAAoEgC,IAOlG,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,mEAAoEK,IAElG,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,mEAAoEO,IAElG,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 5fea796..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index ba411d4..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 own property -* @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 8d275f5..5b81793 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.2.0", - "@stdlib/utils-keys": "^0.2.0", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@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.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..752260d --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 161ca48ee974b8aa043994268badecaae6fa7d95 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 21:26:08 +0000 Subject: [PATCH 088/132] 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 909c8c3..680021a 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@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-map-keys@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.0-esm/index.mjs'; ``` #### mapKeysAsync( obj, \[options,] transform, done ) @@ -340,7 +340,7 @@ The function accepts the same `options` as `mapKeysAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.0-esm/index.mjs'; var files = { 'file1': resolve( __dirname, 'package.json' ), From 4c1d791982581a973bc8149955a7dca3318ba7fa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 21:26:09 +0000 Subject: [PATCH 089/132] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 680021a..d285bcd 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@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-map-keys/tags). For example, + ```javascript import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.0-esm/index.mjs'; ``` @@ -58,7 +63,7 @@ import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map- You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.0-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; ``` #### mapKeysAsync( obj, \[options,] transform, done ) @@ -340,7 +345,7 @@ The function accepts the same `options` as `mapKeysAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.0-esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; var files = { 'file1': resolve( __dirname, 'package.json' ), From 697cbdb0a2efdb46b0009334349e8de939962154 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 16:53:15 +0000 Subject: [PATCH 090/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index f1f529e..527d7c9 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/utils-keys": "^0.2.1", "debug": "^2.6.9" From 7a28036fb6c1245c0588b758101e0c3394c45abb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 18:45:20 +0000 Subject: [PATCH 091/132] Remove files --- index.d.ts | 436 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6618 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b9fd740..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/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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.1.0-esm/index.mjs";function u(e,t){return n(t)?(s(t,"thisArg")&&(e.thisArg=t.thisArg),s(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(i("invalid option. `%s` option must be a boolean. Option: `%s`.","series",e.series)):s(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(i("invalid option. `%s` option must be a positive integer. Option: `%s`.","limit",e.limit)):null):new TypeError(i("invalid argument. Options argument must be an object. Value: `%s`.",t))}function m(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 p=m(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function d(e,t,i,r){var n,s,o,l,u,m,d,f,c;if(o=a(e),m=o.length,p("Number of keys: %d",m),f={},0===m)return p("Finished processing an object."),r(null,f);for(u=m %s: %s",t,JSON.stringify(r)),f[t]=r,h()}}n=o[d+=1],r=e[n],p("%s: %s",n,JSON.stringify(r)),2===i.length?i.call(t.thisArg,n,s):3===i.length?i.call(t.thisArg,n,r,s):i.call(t.thisArg,n,r,e,s)}function h(e){return e?(p("Encountered an error: %s",e.message),r(e)):(p("Processed %d of %d properties.",s+=1,m),d1){if(o=u(s,e))throw o;l=n}else l=e;if(!t(l))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",l));return s.series?s.limit=1:s.limit||(s.limit=r),a;function a(e,r){if("object"!=typeof e||null===e)throw new TypeError(i("invalid argument. First argument must be an object. Value: `%s`.",e));if(!t(r))throw new TypeError(i("invalid argument. Last argument must be a function. Value: `%s`.",r));return d(e,s,l,(function(e,t){if(e)return r(e);r(null,t)}))}}function c(e,t,i,r){if(arguments.length<4)return f(t)(e,i);f(t,i)(e,r)}e(c,"factory",f);export{c as default,f as factory}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5ba3992..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 own property\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' );\nimport objectKeys from '@stdlib/utils-keys';\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","obj","fcn","done","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","length","next","value","key","cb","error","clbk","JSON","stringify","call","message","factory","transform","err","f","arguments","isFunction","PINF","mapKeysAsync","setReadOnly","main"],"mappings":";;q4BAsDA,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,8eC9CIU,uDAAQC,CAAQ,0BAsBpB,SAASH,EAAOI,EAAKb,EAAMc,EAAKC,GAC/B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKQ,OACXf,EAAO,qBAAsBU,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADAV,EAAO,kCACAI,EAAM,KAAMQ,GAapB,IAVCH,EADIC,EAAMrB,EAAKS,MACTY,EAEArB,EAAKS,MAEZE,EAAO,wBAAyBS,GAChCT,EAAO,0BAA2BG,EAAIY,QAEtCV,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVW,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKV,EAAL,CAIA,GAAKY,EAEJ,OADAZ,GAAM,EACCa,EAAMD,GAEdpB,EAAO,6BAA8BkB,EAAKI,KAAKC,UAAWN,IAC1DL,EAAKM,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMX,EADNI,GAAO,GAGPM,EAAQf,EAAKgB,GACblB,EAAO,SAAUkB,EAAKI,KAAKC,UAAWN,IAElB,IAAfd,EAAIY,OACRZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKC,GACH,IAAfhB,EAAIY,OACfZ,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOE,GAEpChB,EAAIqB,KAAMnC,EAAKI,QAASyB,EAAKD,EAAOf,EAAKiB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJpB,EAAO,2BAA4BoB,EAAMK,SAClCrB,EAAMgB,KAGdpB,EAAO,iCADPM,GAAS,EACuCI,GAC3CC,EAAMN,EACHW,IAEHV,IAAUI,GACdV,EAAO,kCACAI,EAAM,KAAMQ,SAFpB,EAIA,CACF,CC9DA,SAASc,EAASpC,EAASqC,GAC1B,IAAItC,EACAuC,EACAC,EAGJ,GADAxC,EAAO,CAAA,EACFyC,UAAUf,OAAS,EAAI,CAE3B,GADAa,EAAMxC,EAAUC,EAAMC,GAErB,MAAMsC,EAEPC,EAAIF,CACN,MACEE,EAAIvC,EAEL,IAAMyC,EAAYF,GACjB,MAAM,IAAIjC,UAAWC,EAAQ,mEAAoEgC,IAOlG,OALKxC,EAAKK,OACTL,EAAKS,MAAQ,EACDT,EAAKS,QACjBT,EAAKS,MAAQkC,GAEPC,EAYP,SAASA,EAAc/B,EAAKE,GAC3B,GAAoB,iBAARF,GAA4B,OAARA,EAC/B,MAAM,IAAIN,UAAWC,EAAQ,mEAAoEK,IAElG,IAAM6B,EAAY3B,GACjB,MAAM,IAAIR,UAAWC,EAAQ,mEAAoEO,IAElG,OAAON,EAAOI,EAAKb,EAAMwC,GAUzB,SAAeT,EAAOR,GACrB,GAAKQ,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMQ,EACZ,GACD,CACF,CC9DA,SAASqB,EAAc/B,EAAKZ,EAASqC,EAAWvB,GAC/C,GAAK0B,UAAUf,OAAS,EACvB,OAAOW,EAASpC,EAAToC,CAAoBxB,EAAKyB,GAEjCD,EAASpC,EAASqC,EAAlBD,CAA+BxB,EAAKE,EACrC,CCpBA8B,EAAAC,EAAA,UAAAT"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 752260d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ea240e035b4da32822227b969d28b312f367da1c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 18:46:46 +0000 Subject: [PATCH 092/132] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 63 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 49 files changed, 4871 insertions(+), 6942 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 (100%) 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 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cd77a66 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.0-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 527d7c9..98ec612 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Map keys from one object to a new object having the same values.", "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,42 +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-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/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-keys": "^0.2.1", - "debug": "^2.6.9" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.0", - "@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..d469931 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 9cc07ee4d98d4f6ef6904e22739b9764dbdec917 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 19:15:55 +0000 Subject: [PATCH 093/132] 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 0a5cac3..ce87991 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@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-map-keys@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.1-esm/index.mjs'; ``` #### mapKeysAsync( obj, \[options,] transform, done ) @@ -340,7 +340,7 @@ The function accepts the same `options` as `mapKeysAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.1-esm/index.mjs'; var files = { 'file1': resolve( __dirname, 'package.json' ), From 6ef8ae2d45b9b4338d8a384344c1b3a096e51d89 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 19:15:56 +0000 Subject: [PATCH 094/132] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce87991..2ad0ee9 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@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-map-keys/tags). For example, + ```javascript import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.1-esm/index.mjs'; ``` @@ -58,7 +63,7 @@ import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map- You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.1-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; ``` #### mapKeysAsync( obj, \[options,] transform, done ) @@ -340,7 +345,7 @@ The function accepts the same `options` as `mapKeysAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.1-esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; var files = { 'file1': resolve( __dirname, 'package.json' ), From ad6f4adafb066ec6e9d22bcae1a269e533581fef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 04:47:09 +0000 Subject: [PATCH 095/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fef3682..b0ad889 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/utils-keys": "^0.2.1", "debug": "^2.6.9", From 26ed1964b4f909ca9d448f6c875e6c1bee84c2a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 09:15:43 +0000 Subject: [PATCH 096/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index cd77a66..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.0-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d469931..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cb5050b6a997d4c0b84e149618184af811221334 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 09:16:00 +0000 Subject: [PATCH 097/132] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 50 files changed, 4871 insertions(+), 6945 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 (100%) 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 e5f4a83..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T03:27:23.717Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f44da25 --- /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@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/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;qxCA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index b0ad889..98ec612 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Map keys from one object to a new object having the same values.", "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-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/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-keys": "^0.2.1", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/random-base-randu": "^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..4458b4c --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 862a79299934896be5d0b18ab2d1d8ca48d82897 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 04:14:41 +0000 Subject: [PATCH 098/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fef3682..b0ad889 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/utils-keys": "^0.2.1", "debug": "^2.6.9", From dd6090f869b560e6f412bbae57a0602ac09e1073 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 08:58:23 +0000 Subject: [PATCH 099/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f44da25..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@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/error-tools-fmtprodmsg@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;qxCA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4458b4c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 067c67b5f1acdfac134a0813ae0fe2a2c477320f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 08:58:34 +0000 Subject: [PATCH 100/132] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 50 files changed, 4871 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 (100%) 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 428a4d9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T02:50:08.604Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..65e67e1 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.1-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index b0ad889..98ec612 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Map keys from one object to a new object having the same values.", "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-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/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-keys": "^0.2.1", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/random-base-randu": "^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..bfda578 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 5c32d0b3eabce46e6617ab025637e316bbfe92ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 00:25:55 +0000 Subject: [PATCH 101/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index fef3682..b0ad889 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.1", "@stdlib/utils-keys": "^0.2.1", "debug": "^2.6.9", From a2aabf1000844fe57e2002ac12437dd10b8b8de9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 05:39:37 +0000 Subject: [PATCH 102/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 65e67e1..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.1-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bfda578..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 037f6a8b782af0cf985b4c15bd88b7c510eaa45d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 05:39:54 +0000 Subject: [PATCH 103/132] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 49 files changed, 4871 insertions(+), 6949 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 (100%) 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 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..65e67e1 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.1-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index b0ad889..98ec612 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Map keys from one object to a new object having the same values.", "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-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/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/utils-keys": "^0.2.1", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.1", - "@stdlib/random-base-randu": "^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..bfda578 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 27ac63aaab561cee93d9399a854a0625ad6a05cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 01:46:55 +0000 Subject: [PATCH 104/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index f16d0ee..8bbc73d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-keys": "^0.2.2", "debug": "^2.6.9", From 47165daa4352b3fff7a54bd482b2fa47838230cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 01:49:41 +0000 Subject: [PATCH 105/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 65e67e1..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.1-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bfda578..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1320ace42da9c493998bfb76e13adae7937596c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 01:49:58 +0000 Subject: [PATCH 106/132] 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 | 197 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 49 files changed, 4871 insertions(+), 7152 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 (100%) 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 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f35ba0f --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8bbc73d..cc944d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Map keys from one object to a new object having the same values.", "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.2", - "@stdlib/assert-is-boolean": "^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/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-keys": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@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..6ed01b4 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 b44c7d39775e03bfaca6b248cd32f750fd3733f7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 01:50:41 +0000 Subject: [PATCH 107/132] 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 32f96f1..a162e21 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@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-map-keys@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.2-esm/index.mjs'; ``` #### mapKeysAsync( obj, \[options,] transform, done ) @@ -340,7 +340,7 @@ The function accepts the same `options` as `mapKeysAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.2-esm/index.mjs'; var files = { 'file1': resolve( __dirname, 'package.json' ), From e344a3b874ec984fb52d1824dd36feb360165d16 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 01:50:42 +0000 Subject: [PATCH 108/132] Auto-generated commit --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a162e21..6ce0c4e 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@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-map-keys/tags). For example, + ```javascript import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.2-esm/index.mjs'; ``` @@ -58,7 +63,7 @@ import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map- You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.2-esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; ``` #### mapKeysAsync( obj, \[options,] transform, done ) @@ -340,7 +345,7 @@ The function accepts the same `options` as `mapKeysAsync()`. var resolve = require( 'path' ).resolve; import readFile from 'https://cdn.jsdelivr.net/gh/stdlib-js/fs-read-file@esm/index.mjs'; -import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@v0.2.2-esm/index.mjs'; +import mapKeysAsync from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-async-map-keys@esm/index.mjs'; var files = { 'file1': resolve( __dirname, 'package.json' ), From d2c70ac3a2b89e54c70e265a513f2ee3f5672736 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 04:48:58 +0000 Subject: [PATCH 109/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4bf8923..ee57081 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-keys": "^0.2.2", "debug": "^2.6.9", From 0598c223457b5dbbf399665eb99a6f84008450bb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 09:02:08 +0000 Subject: [PATCH 110/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f35ba0f..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ed01b4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9fd44568d322bf89e1de2f0b8e9bbcc44f3a9e2e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 09:02:25 +0000 Subject: [PATCH 111/132] 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 | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 50 files changed, 4871 insertions(+), 7116 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 (100%) 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 44d1263..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T03:27:39.733Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f35ba0f --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee57081..cc944d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Map keys from one object to a new object having the same values.", "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.2", - "@stdlib/assert-is-boolean": "^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/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-keys": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@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..6ed01b4 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 b9a05213306e0befed9e5a498c0f17c8063b65f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 19:44:26 +0000 Subject: [PATCH 112/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4bf8923..ee57081 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-keys": "^0.2.2", "debug": "^2.6.9", From 61214151cae3be4c7e51493d38e816816f261d2e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 22:57:37 +0000 Subject: [PATCH 113/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f35ba0f..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ed01b4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 033b3bf893be177ab11d925de2fe12c043c82a26 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 22:57:51 +0000 Subject: [PATCH 114/132] 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 | 197 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 50 files changed, 4871 insertions(+), 7155 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 (100%) 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 e3cfe42..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T18:39:11.793Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f35ba0f --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee57081..cc944d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Map keys from one object to a new object having the same values.", "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.2", - "@stdlib/assert-is-boolean": "^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/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-keys": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@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..6ed01b4 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 3c5cd85b7ae74b76384330c402911bf0c620301a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 04:57:47 +0000 Subject: [PATCH 115/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4bf8923..ee57081 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-keys": "^0.2.2", "debug": "^2.6.9", From 8766a950624f487313d01c52b376e9020dea0ef5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 09:00:07 +0000 Subject: [PATCH 116/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f35ba0f..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ed01b4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 05fe5081f377ad139a4b2a2d547ac89c335de4e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 09:00:24 +0000 Subject: [PATCH 117/132] 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 | 196 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 50 files changed, 4871 insertions(+), 7154 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 (100%) 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 da92bcd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T03:40:28.413Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index e3c70d3..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - `key`: object key - - `value`: object value corresponding to `key` - - `obj`: the input object - - `next`: a callback to be invoked after processing an object `key` - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - `key` - - `next` - - If `transform` accepts three arguments, `transform` is provided: - - - `key` - - `value` - - `next` - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - `error`: error argument - - `key`: transformed key - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f35ba0f --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee57081..cc944d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Map keys from one object to a new object having the same values.", "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.2", - "@stdlib/assert-is-boolean": "^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/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-keys": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@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..6ed01b4 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 7ed60a78f4520ffc1cd0f607dec15b1f70505474 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 21:52:00 +0000 Subject: [PATCH 118/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4bf8923..ee57081 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-keys": "^0.2.2", "debug": "^2.6.9", From 98002a76fa082098b8ff48b36220b3c8d952a43e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 22:17:00 +0000 Subject: [PATCH 119/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f35ba0f..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ed01b4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0d2ca6091320da74c6d38fbd329381794dc03cba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 22:17:15 +0000 Subject: [PATCH 120/132] 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 | 230 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 49 files changed, 4871 insertions(+), 7187 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 (100%) 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 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da4967b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - key: object key. - - value: object value corresponding to `key`. - - obj: the input object. - - next: a callback to be invoked after processing an object `key`. - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - key - - next - - If `transform` accepts three arguments, `transform` is provided: - - - key - - value - - next - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - key: transformed key. - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f35ba0f --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee57081..cc944d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Map keys from one object to a new object having the same values.", "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.2", - "@stdlib/assert-is-boolean": "^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/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-keys": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@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..6ed01b4 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 c036f03adbf77427a4706aae43cd8cd7bdb86dde Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 05:06:50 +0000 Subject: [PATCH 121/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4bf8923..ee57081 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-keys": "^0.2.2", "debug": "^2.6.9", From 012b2edf4b6e4ddf489e7425ec01cf6a98c9046c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 09:09:03 +0000 Subject: [PATCH 122/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f35ba0f..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ed01b4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c1037f11438549e1a0e01512b25b541cc163e30e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 09:09:20 +0000 Subject: [PATCH 123/132] 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 | 230 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 50 files changed, 4871 insertions(+), 7188 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 (100%) 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 c06d5dd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T03:50:24.054Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da4967b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - key: object key. - - value: object value corresponding to `key`. - - obj: the input object. - - next: a callback to be invoked after processing an object `key`. - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - key - - next - - If `transform` accepts three arguments, `transform` is provided: - - - key - - value - - next - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - key: transformed key. - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f35ba0f --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee57081..cc944d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Map keys from one object to a new object having the same values.", "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.2", - "@stdlib/assert-is-boolean": "^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/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-keys": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@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..6ed01b4 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 f0576ff3f2ac5996b13a0446f68ac398f433036d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 05:02:06 +0000 Subject: [PATCH 124/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4bf8923..ee57081 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-keys": "^0.2.2", "debug": "^2.6.9", From bf5ada819dc234ddcd1a8741e5f878678690091c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:38:42 +0000 Subject: [PATCH 125/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f35ba0f..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ed01b4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3919aa0ccb54b341e7e3017d0e2cdc6021ecfcbe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:38:57 +0000 Subject: [PATCH 126/132] 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 | 230 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ----- test/test.js | 38 - test/test.main.js | 1039 ----- test/test.validate.js | 181 - 50 files changed, 4871 insertions(+), 7188 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 (100%) 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 1025414..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T03:53:52.979Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da4967b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - key: object key. - - value: object value corresponding to `key`. - - obj: the input object. - - next: a callback to be invoked after processing an object `key`. - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - key - - next - - If `transform` accepts three arguments, `transform` is provided: - - - key - - value - - next - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - key: transformed key. - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f35ba0f --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee57081..cc944d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Map keys from one object to a new object having the same values.", "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.2", - "@stdlib/assert-is-boolean": "^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/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-keys": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@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..6ed01b4 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 eefef7010afc39f079de33bd46daafe7425ae847 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 05:17:57 +0000 Subject: [PATCH 127/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4bf8923..ee57081 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-keys": "^0.2.2", "debug": "^2.6.9", From 738e6bfe5f04c10ea20ceb210ac2b107186d6ada Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 09:04:21 +0000 Subject: [PATCH 128/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f35ba0f..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ed01b4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2f3c286f6e33b311faa770942e8c913b90ca5d53 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 09:04:33 +0000 Subject: [PATCH 129/132] 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 | 230 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 51 files changed, 4871 insertions(+), 7293 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 (100%) 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 49e3b1a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T03:58:47.574Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4552d44..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da4967b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - key: object key. - - value: object value corresponding to `key`. - - obj: the input object. - - next: a callback to be invoked after processing an object `key`. - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - key - - next - - If `transform` accepts three arguments, `transform` is provided: - - - key - - value - - next - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - key: transformed key. - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f35ba0f --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee57081..cc944d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Map keys from one object to a new object having the same values.", "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.2", - "@stdlib/assert-is-boolean": "^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/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-keys": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@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..6ed01b4 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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 7f9553d0eccff756af740c6c8fa08bc88b5328e0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Jun 2025 00:57:14 +0000 Subject: [PATCH 130/132] 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 5fea796..8b8bc86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -21,7 +21,7 @@ // MODULES // var isFunction = require( '@stdlib/assert-is-function' ); -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' ); @@ -106,7 +106,7 @@ function factory( options, transform ) { f = options; } if ( !isFunction( f ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) ); + throw new TypeError( format( '1RP3q', f ) ); } if ( opts.series ) { opts.limit = 1; @@ -127,10 +127,10 @@ function factory( options, transform ) { */ function mapKeysAsync( obj, done ) { if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + throw new TypeError( format( '1RP3L', obj ) ); } if ( !isFunction( done ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) ); + throw new TypeError( format( '1RP3q', done ) ); } return limit( obj, opts, f, clbk ); diff --git a/lib/validate.js b/lib/validate.js index ba411d4..97d4cf4 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( '1RP2V', 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( '1RP2o', '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( '1RP3P', 'limit', opts.limit ) ); } } return null; diff --git a/package.json b/package.json index 4bf8923..ee57081 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,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/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-keys": "^0.2.2", "debug": "^2.6.9", From 8c1c0b45e3b0ba2590d68fb948f36986471a7f80 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Jun 2025 01:05:43 +0000 Subject: [PATCH 131/132] Remove files --- index.d.ts | 436 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5283 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 ceb6cd7..0000000 --- a/index.d.ts +++ /dev/null @@ -1,436 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 - -/** -* 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 own property (default: false). - */ - series?: boolean; - - /** - * Execution context. - */ - thisArg?: any; -} - -/** -* Callback invoked upon completion. -*/ -type DoneNullary = () => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -*/ -type DoneUnary = ( error: Error | null ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneBinary = ( error: Error | null, out: any ) => void; - -/** -* Callback invoked upon completion. -* -* @param error - encountered error or null -* @param out - output object -*/ -type DoneCallback = DoneNullary | DoneUnary | DoneBinary; - -/** -* 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 group - value group -*/ -type Binary = ( error: Error | null, group: string ) => void; - -/** -* Callback function. -* -* @param error - encountered error or null -* @param group - value group -*/ -type Callback = Nullary | Unary | Binary; - -/** -* Transform function. -* -* @param key - object key -* @param next - a callback to be invoked after processing an object `value` -*/ -type BinaryTransform = ( value: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param next - a callback to be invoked after processing an object `value` -*/ -type TernaryTransform = ( value: any, index: number, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type QuaternaryTransform = ( value: any, index: number, obj: any, next: Callback ) => void; - -/** -* Transform function. -* -* @param key - object key -* @param value - object value corresponding to `key` -* @param obj - the input object -* @param next - a callback to be invoked after processing an object `value` -*/ -type Transform = Unary | BinaryTransform | TernaryTransform | QuaternaryTransform; - -/** -* Maps keys from one object to a new object having the same values. -* -* @param obj - the input object -* @param done - function to invoke upon completion -*/ -type FactoryFunction = ( obj: any, done: DoneCallback ) => void; - -/** -* Interface for `mapKeysAsync`. -*/ -interface MapKeysAsync { - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @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 own property (default: false) - * @param transform - transform function - * @param done - function to invoke upon completion - * @throws must provide valid options - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * var opts = { - * 'series': true - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, opts, read, done ); - */ - ( obj: any, options: Options, transform: Transform, done: DoneCallback ): void; - - /** - * Maps keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param obj - source object - * @param transform - transform function - * @param done - function to invoke upon completion - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Process each file in `files`: - * mapKeysAsync( files, read, done ); - */ - ( obj: any, transform: Transform, done: DoneCallback ): void; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @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 own property (default: false) - * @param transform - transform function - * @throws must provide valid options - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * var opts = { - * 'series': true - * }; - * - * // Create a reusable function: - * var mapKeysAsync = factory( opts, read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( options: Options, transform: Transform ): FactoryFunction; - - /** - * Returns a function to map keys from one object to a new object having the same values. - * - * ## Notes - * - * - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. - * - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). - * - Iteration and insertion order are **not** guaranteed. - * - The function only operates on own properties, not inherited properties. - * - * - * @param transform - transform function - * @returns function which maps keys from one object to a new object having the same values - * - * @example - * var readFile = require( '@stdlib/fs-read-file' ); - * - * function read( key, value, next ) { - * var opts = { - * 'encoding': 'utf8' - * }; - * readFile( value, opts, onFile ); - * - * function onFile( error ) { - * if ( error ) { - * return next( null, key+':unreadable' ); - * } - * next( null, key+':readable' ); - * } - * } - * - * // Create a reusable function: - * var mapKeysAsync = factory( read ); - * - * // Create a dictionary of file names: - * var files = { - * 'file1': './beep.js', - * 'file2': './boop.js' - * }; - * - * // Define a callback which handles errors: - * function done( error, out ) { - * if ( error ) { - * throw error; - * } - * console.log( out ); - * } - * - * // Process each file in `files`: - * mapKeysAsync( files, done ); - */ - factory( transform: Transform ): FactoryFunction; -} - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* -* @param obj - source object -* @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 own property (default: false) -* @param transform - transform function -* @param done - function to invoke upon completion -* @throws must provide valid options -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -declare var mapKeysAsync: MapKeysAsync; - - -// EXPORTS // - -export = mapKeysAsync; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f35ba0f..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6ed01b4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3e867b3127cf6a3bdf890274a0e399a216957ee9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 23 Jun 2025 01:05:58 +0000 Subject: [PATCH 132/132] 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 | 230 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.factory.js | 69 - benchmark/benchmark.js | 148 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 187 - docs/types/test.ts | 166 - examples/index.js | 51 - docs/types/index.d.ts => index.d.ts | 0 index.mjs | 4 + index.mjs.map | 1 + lib/factory.js | 157 - lib/index.js | 80 - lib/limit.js | 160 - lib/main.js | 100 - lib/validate.js | 80 - package.json | 64 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 1124 ---- test/test.js | 38 - test/test.main.js | 1039 ---- test/test.validate.js | 181 - 51 files changed, 4871 insertions(+), 7296 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 (100%) 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 b977dae..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-23T00:55:49.133Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index f7fe930..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/map-keys) 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 bf16323..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/map-keys) 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 b924aaf..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: '21 9 * * 0' - - # 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 + + ```
@@ -414,7 +411,7 @@ mapKeysAsync( files, 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]. @@ -481,9 +478,9 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys +[@stdlib/utils/map-keys]: https://github.com/stdlib-js/utils-map-keys/tree/esm -[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values +[@stdlib/utils/async/map-values]: https://github.com/stdlib-js/utils-async-map-values/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 30c0aab..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var factory = require( './../lib/factory.js' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var mapKeysAsync; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - mapKeysAsync = factory( transform ); - - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4f0add9..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,148 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 randu = require( '@stdlib/random-base-randu' ); -var pkg = require( './../package.json' ).name; -var mapKeysAsync = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':series=true', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'series': true - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); - -bench( pkg+':limit=3', function benchmark( b ) { - var opts; - var obj; - var i; - - function transform( k, v, clbk ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - clbk( null, k+':'+v ); - } - } - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar', - 'e': randu() - }; - opts = { - 'limit': 3 - }; - i = 0; - b.tic(); - - return next(); - - function next( error ) { - i += 1; - if ( error ) { - b.fail( 'should not return an error' ); - } - if ( i <= b.iterations ) { - obj.e = randu(); - return mapKeysAsync( obj, opts, transform, next ); - } - b.toc(); - b.pass( 'benchmark finished' ); - b.end(); - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 852998d..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/map-keys" -%% click B href "https://github.com/stdlib-js/utils-async-map-keys/tree/main" -%% click C href "https://github.com/stdlib-js/utils-async-map-keys/tree/production" -%% click D href "https://github.com/stdlib-js/utils-async-map-keys/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-async-map-keys/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-async-map-keys/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/async/map-keys -[production-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/production -[deno-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-async-map-keys/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-async-map-keys/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-async-map-keys/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 e389755..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapKeysAsync from '../docs/types/index'; -export = mapKeysAsync; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eea6508..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var P=y(function(Z,T){ -var S=require('@stdlib/assert-is-plain-object/dist'),q=require('@stdlib/assert-has-own-property/dist'),j=require('@stdlib/assert-is-boolean/dist').isPrimitive,B=require('@stdlib/assert-is-positive-integer/dist').isPrimitive,b=require('@stdlib/error-tools-fmtprodmsg/dist');function C(e,r){return S(r)?(q(r,"thisArg")&&(e.thisArg=r.thisArg),q(r,"series")&&(e.series=r.series,!j(e.series))?new TypeError(b('1RP2o',"series",e.series)):q(r,"limit")&&(e.limit=r.limit,!B(e.limit))?new TypeError(b('1RP3P',"limit",e.limit)):null):new TypeError(b('1RP2V',r));}T.exports=C -});var N=y(function(_,F){ -var R=require("debug"),z=require('@stdlib/utils-keys/dist'),s=R("map-values-async:limit");function D(e,r,i,n){var u,v,l,f,c,t,m,o,h;if(l=z(e),t=l.length,s("Number of keys: %d",t),o={},t===0)return s("Finished processing an object."),n(null,o);for(t %s: %s",E,JSON.stringify(a)),o[E]=a,A()}}}function A(a){if(a)return s("Encountered an error: %s",a.message),n(a);if(v+=1,s("Processed %d of %d properties.",v,t),m1){if(n=H(i,e),n)throw n;u=r}else u=e;if(!k(u))throw new TypeError(w('1RP3q',u));return i.series?i.limit=1:i.limit||(i.limit=G),v;function v(l,f){if(typeof l!="object"||l===null)throw new TypeError(w('1RP3L',l));if(!k(f))throw new TypeError(w('1RP3q',f));return M(l,i,u,c);function c(t,m){if(t)return f(t);f(null,m)}}}V.exports=Q -});var J=y(function(rr,K){ -var I=p();function U(e,r,i,n){if(arguments.length<4)return I(r)(e,i);I(r,i)(e,n)}K.exports=U -});var W=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),L=J(),X=p();W(L,"factory",X);module.exports=L; -/** @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 002f961..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 own property\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' );\nvar objectKeys = require( '@stdlib/utils-keys' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'map-values-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions.\n*\n* ## Notes\n*\n* - Iteration order is **not** guaranteed.\n* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.\n*\n* @private\n* @param {Object} obj - source object\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( obj, opts, fcn, done ) {\n\tvar maxIndex;\n\tvar count;\n\tvar keys;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar out;\n\tvar i;\n\n\tkeys = objectKeys( obj );\n\tlen = keys.length;\n\tdebug( 'Number of keys: %d', len );\n\n\tout = {};\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing an object.' );\n\t\treturn done( null, out );\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\tmaxIndex = len - 1;\n\tcount = 0;\n\tidx = -1;\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all properties...\n\t\tif ( idx < maxIndex ) {\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 property.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tvar value;\n\t\tvar key;\n\n\t\tidx += 1;\n\t\tkey = keys[ idx ];\n\n\t\tvalue = obj[ key ];\n\t\tdebug( '%s: %s', key, JSON.stringify( value ) );\n\n\t\tif ( fcn.length === 2 ) {\n\t\t\tfcn.call( opts.thisArg, key, cb );\n\t\t} else if ( fcn.length === 3 ) {\n\t\t\tfcn.call( opts.thisArg, key, value, cb );\n\t\t} else {\n\t\t\tfcn.call( opts.thisArg, key, value, obj, cb );\n\t\t}\n\t\t/**\n\t\t* Callback invoked once a provided function finishes transforming a property.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {*} [key] - transformed key\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction cb( error, key ) {\n\t\t\tif ( flg ) {\n\t\t\t\t// Prevent further processing of properties:\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( 'Transform result => %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) );\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( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapKeysAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' );\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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,EAC1BC,EAAa,QAAS,oBAAqB,EAK3CC,EAAQF,EAAQ,wBAAyB,EAsB7C,SAASG,EAAOC,EAAKC,EAAMC,EAAKC,EAAO,CACtC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOT,EAAYG,CAAI,EACvBS,EAAMH,EAAK,OACXR,EAAO,qBAAsBW,CAAI,EAEjCE,EAAM,CAAC,EACFF,IAAQ,EACZ,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,EAaxB,IAXKF,EAAMR,EAAK,MACfO,EAAMC,EAEND,EAAMP,EAAK,MAEZH,EAAO,wBAAyBU,CAAI,EACpCV,EAAO,0BAA2BI,EAAI,MAAO,EAE7CE,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,EAAM,GACAE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVS,EAAK,EAQP,SAASA,GAAO,CACf,IAAIC,EACAC,EAEJL,GAAO,EACPK,EAAMT,EAAMI,CAAI,EAEhBI,EAAQd,EAAKe,CAAI,EACjBjB,EAAO,SAAUiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAEzCZ,EAAI,SAAW,EACnBA,EAAI,KAAMD,EAAK,QAASc,EAAKC,CAAG,EACrBd,EAAI,SAAW,EAC1BA,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOE,CAAG,EAEvCd,EAAI,KAAMD,EAAK,QAASc,EAAKD,EAAOd,EAAKgB,CAAG,EAU7C,SAASA,EAAIC,EAAOF,EAAM,CACzB,GAAK,CAAAR,EAIL,IAAKU,EACJ,OAAAV,EAAM,GACCW,EAAMD,CAAM,EAEpBnB,EAAO,6BAA8BiB,EAAK,KAAK,UAAWD,CAAM,CAAE,EAClEH,EAAKI,CAAI,EAAID,EACbI,EAAK,EACN,CACD,CASA,SAASA,EAAMD,EAAQ,CACtB,GAAKA,EACJ,OAAAnB,EAAO,2BAA4BmB,EAAM,OAAQ,EAC1Cd,EAAMc,CAAM,EAIpB,GAFAZ,GAAS,EACTP,EAAO,iCAAkCO,EAAOI,CAAI,EAC/CC,EAAMN,EACV,OAAOS,EAAK,EAEb,GAAKR,IAAUI,EACd,OAAAX,EAAO,gCAAiC,EACjCK,EAAM,KAAMQ,CAAI,CAEzB,CACD,CAKAhB,EAAO,QAAUI,IC/JjB,IAAAoB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAkEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACN,EAAYU,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAYP,SAASA,EAAcC,EAAKC,EAAO,CAClC,GAAK,OAAOD,GAAQ,UAAYA,IAAQ,KACvC,MAAM,IAAI,UAAWX,EAAQ,mEAAoEW,CAAI,CAAE,EAExG,GAAK,CAACZ,EAAYa,CAAK,EACtB,MAAM,IAAI,UAAWZ,EAAQ,mEAAoEY,CAAK,CAAE,EAEzG,OAAOT,EAAOQ,EAAKJ,EAAME,EAAGI,CAAK,EAUjC,SAASA,EAAMC,EAAOC,EAAM,CAC3B,GAAKD,EACJ,OAAOF,EAAME,CAAM,EAEpBF,EAAM,KAAMG,CAAI,CACjB,CACD,CACD,CAKAjB,EAAO,QAAUM,IC5JjB,IAAAY,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAU,IAmEd,SAASC,EAAcC,EAAKC,EAASC,EAAWC,EAAO,CACtD,GAAK,UAAU,OAAS,EACvB,OAAOL,EAASG,CAAQ,EAAGD,EAAKE,CAAU,EAE3CJ,EAASG,EAASC,CAAU,EAAGF,EAAKG,CAAK,CAC1C,CAKAN,EAAO,QAAUE,IChCjB,IAAIK,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", "objectKeys", "debug", "limit", "obj", "opts", "fcn", "done", "maxIndex", "count", "keys", "flg", "lim", "len", "idx", "out", "i", "next", "value", "key", "cb", "error", "clbk", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "format", "PINF", "validate", "limit", "factory", "options", "transform", "opts", "err", "f", "mapKeysAsync", "obj", "done", "clbk", "error", "out", "require_main", "__commonJSMin", "exports", "module", "factory", "mapKeysAsync", "obj", "options", "transform", "done", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index da4967b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,187 +0,0 @@ - -{{alias}}( obj, [options,] transform, done ) - Maps keys from one object to a new object having the same values. - - When invoked, `transform` is provided a maximum of four arguments: - - - key: object key. - - value: object value corresponding to `key`. - - obj: the input object. - - next: a callback to be invoked after processing an object `key`. - - The actual number of provided arguments depends on function length. If - `transform` accepts two arguments, `transform` is provided: - - - key - - next - - If `transform` accepts three arguments, `transform` is provided: - - - key - - value - - next - - For every other `transform` signature, `transform` is provided all four - arguments. - - The `next` callback accepts two arguments: - - - error: error argument. - - key: transformed key. - - If a `transform` 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 key returned by a transform function should be a value which can be - serialized as an object key. - - 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 only maps own properties. Hence, the function does not map - inherited properties. - - The function shallow copies key values. - - Key iteration and insertion order are *not* guaranteed. - - Parameters - ---------- - obj: Object - Source object. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - done: Function - A callback invoked either upon processing all own properties or upon - encountering an error. - - Examples - -------- - // Basic usage: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2 }; - > {{alias}}( obj, transform, done ) - { 'a:1': 1, 'b:2': 2 } - - // Limit number of concurrent invocations: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'limit': 2 }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - // Process sequentially: - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var opts = { 'series': true }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > {{alias}}( obj, opts, transform, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - - -{{alias}}.factory( [options,] transform ) - Returns a function which maps keys from one object to a new object having - the same values. - - 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 property sequentially. - Default: false. - - options.thisArg: any (optional) - Execution context. - - transform: Function - Transform function. Returned values specify the keys of the output - object. - - Returns - ------- - out: Function - A function which maps keys from one object to a new object having the - same values. - - Examples - -------- - > function transform( key, value, next ) { - ... setTimeout( onTimeout, value ); - ... function onTimeout() { - ... next( null, key+':'+value ); - ... } - ... }; - > var opts = { 'series': true }; - > var f = {{alias}}.factory( opts, transform ); - > function done( error, out ) { - ... if ( error ) { - ... throw error; - ... } - ... console.log( out ); - ... }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > f( obj, done ) - { 'a:1': 1, 'b:2': 2, 'c:3': 3 } - > obj = { 'beep': 'boop' }; - > f( obj, done ) - { 'beep:boop': 'beep' } - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 9973076..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. -*/ - -import mapKeysAsync = require( './index' ); - -const transform = ( key: string, next: Function ) => { - next( null, key + ':beep' ); -}; - -const done = ( error: Error | null, out: any ) => { - if ( error ) { - throw error; - } - if ( out === void 0 ) { - throw new Error( '`out` is missing.' ); - } -}; - - -// TESTS // - -// The function returns void... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, done ); // $ExpectType void -} - -// The compiler throws an error if the function is provided a second argument which is not a transform function... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, 2, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, [], 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... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 2 ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, false ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, true ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, 'abc' ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, {} ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, [] ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, [], transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 123, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, 'abc', transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, false, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, true, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `limit` option which is not a number... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': true }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': false }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'limit': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `series` option which is not a boolean... -{ - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': '12' }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': 12 }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': {} }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': [] }, transform, done ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, { 'series': ( x: number ): number => x }, transform, done ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - mapKeysAsync(); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 } ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, transform ); // $ExpectError - mapKeysAsync( { 'a': 1, 'b': 2 }, {}, transform, done, {} ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - mapKeysAsync.factory( transform ); // $ExpectType FactoryFunction - mapKeysAsync.factory( { 'series': true }, transform ); // $ExpectType FactoryFunction -} - -// The compiler throws an error if the `factory` method is provided an options argument which is not an object... -{ - mapKeysAsync.factory( [], transform ); // $ExpectError - mapKeysAsync.factory( 123, transform ); // $ExpectError - mapKeysAsync.factory( 'abc', transform ); // $ExpectError - mapKeysAsync.factory( false, transform ); // $ExpectError - mapKeysAsync.factory( true, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a last argument which is not an transform function... -{ - mapKeysAsync.factory( {} ); // $ExpectError - mapKeysAsync.factory( true ); // $ExpectError - mapKeysAsync.factory( false ); // $ExpectError - mapKeysAsync.factory( {}, 123 ); // $ExpectError - mapKeysAsync.factory( {}, 'abc' ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... -{ - const fcn1 = mapKeysAsync.factory( transform ); - fcn1( { 'a': 1, 'b': 2 }, 12 ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, true ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, false ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, '5' ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, {} ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, [] ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, ( 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 fcn1 = mapKeysAsync.factory( transform ); - fcn1(); // $ExpectError - fcn1( { 'a': 1, 'b': 2 } ); // $ExpectError - fcn1( { 'a': 1, 'b': 2 }, done, {} ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `limit` option which is not a number... -{ - mapKeysAsync.factory( { 'limit': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': true }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': false }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'limit': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `series` option which is not a boolean... -{ - mapKeysAsync.factory( { 'series': '12' }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': 12 }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': {} }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': [] }, transform ); // $ExpectError - mapKeysAsync.factory( { 'series': ( x: number ): number => x }, transform ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an invalid number of arguments... -{ - mapKeysAsync.factory(); // $ExpectError - mapKeysAsync.factory( {}, transform, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 08bf70d..0000000 --- a/examples/index.js +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 mapKeysAsync = require( './../lib' ); - -var files = { - 'file1': resolve( __dirname, '..', 'package.json' ), - 'file2': resolve( __dirname, '..', 'README.md' ) -}; - -function read( key, value, next ) { - var opts = { - 'encoding': 'utf8' - }; - readFile( value, opts, onFile ); - - function onFile( error ) { - if ( error ) { - return next( error, key+':unreadable' ); - } - next( null, key+':readable' ); - } -} - -function done( error, out ) { - if ( error ) { - throw error; - } - console.log( out ); -} - -mapKeysAsync( files, read, done ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 100% rename from docs/types/index.d.ts rename to index.d.ts diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8fa09bd --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import{isPrimitive as o}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import{isPrimitive as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-keys@v0.2.2-esm/index.mjs";function f(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var i=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:function(){return e[t]}})})),r}var d=f(Object.freeze({__proto__:null,default:()=>()=>{}}))("map-values-async:limit");function c(e,f){var c,u,p;if(c={},arguments.length>1){if(u=function(e,t){return s(t)?(n(t,"thisArg")&&(e.thisArg=t.thisArg),n(t,"series")&&(e.series=t.series,!o(e.series))?new TypeError(r("1RP2o","series",e.series)):n(t,"limit")&&(e.limit=t.limit,!l(e.limit))?new TypeError(r("1RP3P","limit",e.limit)):null):new TypeError(r("1RP2V",t))}(c,e),u)throw u;p=f}else p=e;if(!t(p))throw new TypeError(r("1RP3q",p));return c.series?c.limit=1:c.limit||(c.limit=i),function(e,i){if("object"!=typeof e||null===e)throw new TypeError(r("1RP3L",e));if(!t(i))throw new TypeError(r("1RP3q",i));return function(e,t,r,i){var s,n,o,l,f,c,u,p,a;if(o=m(e),c=o.length,d("Number of keys: %d",c),p={},0===c)return d("Finished processing an object."),i(null,p);for(f=c %s: %s",t,JSON.stringify(i)),p[t]=i,j()}}s=o[u+=1],i=e[s],d("%s: %s",s,JSON.stringify(i)),2===r.length?r.call(t.thisArg,s,n):3===r.length?r.call(t.thisArg,s,i,n):r.call(t.thisArg,s,i,e,n)}function j(e){return e?(d("Encountered an error: %s",e.message),i(e)):(d("Processed %d of %d properties.",n+=1,c),u %s: %s', key, JSON.stringify( value ) );\n\t\t\tout[ key ] = value;\n\t\t\tclbk();\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once ready to process the next property.\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 properties.', count, len );\n\t\tif ( idx < maxIndex ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing an object.' );\n\t\t\treturn done( null, out );\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 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 map keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\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 maps keys from one object to a new object having the same values\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a reusable function:\n* var mapKeysAsync = factory( opts, read );\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, done );\n*/\nfunction factory( options, transform ) {\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 = transform;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( '1RP3q', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn mapKeysAsync;\n\n\t/**\n\t* Maps keys from one object to a new object having the same values.\n\t*\n\t* @private\n\t* @param {Object} obj - source object\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be an object\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction mapKeysAsync( obj, done ) {\n\t\tif ( typeof obj !== 'object' || obj === null ) {\n\t\t\tthrow new TypeError( format( '1RP3L', obj ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( '1RP3q', done ) );\n\t\t}\n\t\treturn limit( obj, 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 {Object} [out] - output object\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, out ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error );\n\t\t\t}\n\t\t\tdone( null, out );\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 own property\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( '1RP2V', 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( '1RP2o', '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( '1RP3P', '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* Maps keys from one object to a new object having the same values.\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* - Iteration and insertion order are **not** guaranteed.\n* - The function only operates on own properties, not inherited properties.\n*\n* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property\n* @param {Function} transform - transform function\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be an object\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 read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, read, done );\n*/\nfunction mapKeysAsync( obj, options, transform, done ) {\n\tif ( arguments.length < 4 ) {\n\t\treturn factory( options )( obj, transform );\n\t}\n\tfactory( options, transform )( obj, done );\n}\n\n\n// EXPORTS //\n\nexport default mapKeysAsync;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Map keys from one object to a new object having the same values.\n*\n* @module @stdlib/utils-async-map-keys\n*\n* @example\n* import readFile from '@stdlib/fs-read-file';\n* import mapKeysAsync from '@stdlib/utils-async-map-keys';\n*\n* function read( key, value, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( value, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, key+':unreadable' );\n* }\n* next( null, key+':readable' );\n* }\n* }\n*\n* // Define a callback which handles errors:\n* function done( error, out ) {\n* if ( error ) {\n* throw error;\n* }\n* console.log( out );\n* }\n*\n* // Create a dictionary of file names:\n* var files = {\n* 'file1': './beep.js',\n* 'file2': './boop.js'\n* };\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Process each file in `files`:\n* mapKeysAsync( files, opts, 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","transform","opts","err","f","arguments","length","isObject","hasOwnProp","thisArg","series","isBoolean","TypeError","format","limit","isPositiveInteger","validate","isFunction","PINF","obj","done","fcn","maxIndex","count","keys","flg","lim","len","idx","out","i","objectKeys","next","value","key","cb","error","clbk","JSON","stringify","call","message","mapKeysAsync","setReadOnly","main"],"mappings":";;o1CA4BIA,uDAAQC,CAAQ,0BCgEpB,SAASC,EAASC,EAASC,GAC1B,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAA,EACFG,UAAUC,OAAS,EAAI,CAE3B,GADAH,EC7CF,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,CDyBQgB,CAAUd,EAAMF,GACjBG,EACJ,MAAMA,EAEPC,EAAIH,CACN,MACEG,EAAIJ,EAEL,IAAMiB,EAAYb,GACjB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAOvC,OALKF,EAAKQ,OACTR,EAAKY,MAAQ,EACDZ,EAAKY,QACjBZ,EAAKY,MAAQI,GAcd,SAAuBC,EAAKC,GAC3B,GAAoB,iBAARD,GAA4B,OAARA,EAC/B,MAAM,IAAIP,UAAWC,EAAQ,QAASM,IAEvC,IAAMF,EAAYG,GACjB,MAAM,IAAIR,UAAWC,EAAQ,QAASO,IAEvC,ODpFF,SAAgBD,EAAKjB,EAAMmB,EAAKD,GAC/B,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAOJ,GALAN,EAAOO,EAAYZ,GACnBQ,EAAMH,EAAKlB,OACXT,EAAO,qBAAsB8B,GAE7BE,EAAM,CAAA,EACO,IAARF,EAEJ,OADA9B,EAAO,kCACAuB,EAAM,KAAMS,GAapB,IAVCH,EADIC,EAAMzB,EAAKY,MACTa,EAEAzB,EAAKY,MAEZjB,EAAO,wBAAyB6B,GAChC7B,EAAO,0BAA2BwB,EAAIf,QAEtCgB,EAAWK,EAAM,EACjBJ,EAAQ,EACRK,GAAO,EACDE,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAMN,GACVU,IAQF,SAASA,IACR,IAAIC,EACAC,EAuBJ,SAASC,EAAIC,EAAOF,GACnB,IAAKT,EAAL,CAIA,GAAKW,EAEJ,OADAX,GAAM,EACCY,EAAMD,GAEdvC,EAAO,6BAA8BqC,EAAKI,KAAKC,UAAWN,IAC1DJ,EAAKK,GAAQD,EACbI,GAPC,CAQD,CAhCDH,EAAMV,EADNI,GAAO,GAGPK,EAAQd,EAAKe,GACbrC,EAAO,SAAUqC,EAAKI,KAAKC,UAAWN,IAElB,IAAfZ,EAAIf,OACRe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKC,GACH,IAAfd,EAAIf,OACfe,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOE,GAEpCd,EAAImB,KAAMtC,EAAKO,QAASyB,EAAKD,EAAOd,EAAKgB,EAuB1C,CASD,SAASE,EAAMD,GACd,OAAKA,GACJvC,EAAO,2BAA4BuC,EAAMK,SAClCrB,EAAMgB,KAGdvC,EAAO,iCADP0B,GAAS,EACuCI,GAC3CC,EAAMN,EACHU,IAEHT,IAAUI,GACd9B,EAAO,kCACAuB,EAAM,KAAMS,SAFpB,EAIA,CACF,CCpBSf,CAAOK,EAAKjB,EAAME,GAUzB,SAAegC,EAAOP,GACrB,GAAKO,EACJ,OAAOhB,EAAMgB,GAEdhB,EAAM,KAAMS,EACZ,GACD,CACF,CE9DA,SAASa,EAAcvB,EAAKnB,EAASC,EAAWmB,GAC/C,GAAKf,UAAUC,OAAS,EACvB,OAAOP,EAASC,EAATD,CAAoBoB,EAAKlB,GAEjCF,EAASC,EAASC,EAAlBF,CAA+BoB,EAAKC,EACrC,CCpBAuB,EAAAC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 8b8bc86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,157 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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 map keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @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 maps keys from one object to a new object having the same values -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* var opts = { -* 'series': true -* }; -* -* // Create a reusable function: -* var mapKeysAsync = factory( opts, read ); -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Process each file in `files`: -* mapKeysAsync( files, done ); -*/ -function factory( options, transform ) { - var opts; - var err; - var f; - - opts = {}; - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - f = transform; - } else { - f = options; - } - if ( !isFunction( f ) ) { - throw new TypeError( format( '1RP3q', f ) ); - } - if ( opts.series ) { - opts.limit = 1; - } else if ( !opts.limit ) { - opts.limit = PINF; - } - return mapKeysAsync; - - /** - * Maps keys from one object to a new object having the same values. - * - * @private - * @param {Object} obj - source object - * @param {Callback} done - function to invoke upon completion - * @throws {TypeError} first argument must be an object - * @throws {TypeError} last argument must be a function - * @returns {void} - */ - function mapKeysAsync( obj, done ) { - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( '1RP3L', obj ) ); - } - if ( !isFunction( done ) ) { - throw new TypeError( format( '1RP3q', done ) ); - } - return limit( obj, opts, f, clbk ); - - /** - * Callback invoked upon completion. - * - * @private - * @param {*} [error] - error - * @param {Object} [out] - output object - * @returns {void} - */ - function clbk( error, out ) { - if ( error ) { - return done( error ); - } - done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 1bdda48..0000000 --- a/lib/index.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'; - -/** -* Map keys from one object to a new object having the same values. -* -* @module @stdlib/utils-async-map-keys -* -* @example -* var readFile = require( '@stdlib/fs-read-file' ); -* var mapKeysAsync = require( '@stdlib/utils-async-map-keys' ); -* -* function read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, 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 17d7792..0000000 --- a/lib/limit.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 logger = require( 'debug' ); -var objectKeys = require( '@stdlib/utils-keys' ); - - -// VARIABLES // - -var debug = logger( 'map-values-async:limit' ); - - -// MAIN // - -/** -* Invokes a function once for each own property in a source object, limiting the number of concurrently pending functions. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* - We need to cache an object value to prevent the edge case where, during the invocation of the transform function, the value corresponding to a particular key is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever. -* -* @private -* @param {Object} obj - source object -* @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( obj, opts, fcn, done ) { - var maxIndex; - var count; - var keys; - var flg; - var lim; - var len; - var idx; - var out; - var i; - - keys = objectKeys( obj ); - len = keys.length; - debug( 'Number of keys: %d', len ); - - out = {}; - if ( len === 0 ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - if ( len < opts.limit ) { - lim = len; - } else { - lim = opts.limit; - } - debug( 'Concurrency limit: %d', lim ); - debug( 'Number of arguments: %d', fcn.length ); - - maxIndex = len - 1; - count = 0; - idx = -1; - for ( i = 0; i < lim; i++ ) { - // This guard is necessary to protect against synchronous functions which exhaust all properties... - if ( idx < maxIndex ) { - next(); // eslint-disable-line node/callback-return - } - } - /** - * Callback to invoke a provided function for the next property. - * - * @private - */ - function next() { - var value; - var key; - - idx += 1; - key = keys[ idx ]; - - value = obj[ key ]; - debug( '%s: %s', key, JSON.stringify( value ) ); - - if ( fcn.length === 2 ) { - fcn.call( opts.thisArg, key, cb ); - } else if ( fcn.length === 3 ) { - fcn.call( opts.thisArg, key, value, cb ); - } else { - fcn.call( opts.thisArg, key, value, obj, cb ); - } - /** - * Callback invoked once a provided function finishes transforming a property. - * - * @private - * @param {*} [error] - error - * @param {*} [key] - transformed key - * @returns {void} - */ - function cb( error, key ) { - if ( flg ) { - // Prevent further processing of properties: - return; - } - if ( error ) { - flg = true; - return clbk( error ); - } - debug( 'Transform result => %s: %s', key, JSON.stringify( value ) ); - out[ key ] = value; - clbk(); - } - } - - /** - * Callback invoked once ready to process the next property. - * - * @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 properties.', count, len ); - if ( idx < maxIndex ) { - return next(); - } - if ( count === len ) { - debug( 'Finished processing an object.' ); - return done( null, out ); - } - } -} - - -// EXPORTS // - -module.exports = limit; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4f0fb6e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,100 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 // - -/** -* Maps keys from one object to a new object having the same values. -* -* ## Notes -* -* - If a provided function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling. -* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`). -* - Iteration and insertion order are **not** guaranteed. -* - The function only operates on own properties, not inherited properties. -* -* @param {Object} obj - source 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=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next own property -* @param {Function} transform - transform function -* @param {Callback} done - function to invoke upon completion -* @throws {TypeError} first argument must be an object -* @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 read( key, value, next ) { -* var opts = { -* 'encoding': 'utf8' -* }; -* readFile( value, opts, onFile ); -* -* function onFile( error ) { -* if ( error ) { -* return next( null, key+':unreadable' ); -* } -* next( null, key+':readable' ); -* } -* } -* -* // Define a callback which handles errors: -* function done( error, out ) { -* if ( error ) { -* throw error; -* } -* console.log( out ); -* } -* -* // Create a dictionary of file names: -* var files = { -* 'file1': './beep.js', -* 'file2': './boop.js' -* }; -* -* var opts = { -* 'series': true -* }; -* -* // Process each file in `files`: -* mapKeysAsync( files, opts, read, done ); -*/ -function mapKeysAsync( obj, options, transform, done ) { - if ( arguments.length < 4 ) { - return factory( options )( obj, transform ); - } - factory( options, transform )( obj, done ); -} - - -// EXPORTS // - -module.exports = mapKeysAsync; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 97d4cf4..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 own property -* @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( '1RP2V', 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( '1RP2o', 'series', opts.series ) ); - } - } - if ( hasOwnProp( options, 'limit' ) ) { - opts.limit = options.limit; - if ( !isPositiveInteger( opts.limit ) ) { - return new TypeError( format( '1RP3P', 'limit', opts.limit ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index ee57081..cc944d7 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Map keys from one object to a new object having the same values.", "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.2", - "@stdlib/assert-is-boolean": "^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/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/utils-keys": "^0.2.2", - "debug": "^2.6.9", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/fs-read-file": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@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..6ed01b4 --- /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 cf9be29..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,1124 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 own property in an object (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 own property in an object (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( key, clbk ) { - clbk( null, key ); - } - - 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( key, clbk ) { - clbk( null, key ); - } - - 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( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - function next( value, clbk ) { - clbk( null, value ); - } - t.strictEqual( typeof factory( {}, next ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the returned function throws an error if not provided an object (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided an object (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - mapKeysAsync( value, noop ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (no options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function throws an error if not provided a callback function (options)', function test( t ) { - var mapKeysAsync; - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - mapKeysAsync = 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() { - var obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, value ); - }; - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function returns a function which invokes a provided function with four arguments (1 argument)', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function returns a function which invokes a provided function with four arguments', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the returned function processes object properties concurrently', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (in series)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function for processing object properties sequentially (limit = 1)', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports returning a function which limits the maximum number of object properties which are processed at any one time', function test( t ) { - var mapKeysAsync; - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var mapKeysAsync; - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, key ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (series)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, 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 an object property, the returned function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var mapKeysAsync; - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - mapKeysAsync = factory( opts, fcn ); - - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the returned function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var mapKeysAsync; - var count; - var obj; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, done ); - - function fcn( key, value, 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( 'the returned function ignores inherited properties', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function accepts non-plain objects', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the returned function returns a shallow copy', function test( t ) { - var mapKeysAsync; - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj1, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the returned function never invokes a provided function', function test( t ) { - var mapKeysAsync; - var obj; - - mapKeysAsync = factory( fcn ); - obj = {}; - - mapKeysAsync( obj, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the returned function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var mapKeysAsync; - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync = factory( fcn ); - mapKeysAsync( obj, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the returned function does not guarantee asynchronous execution', function test( t ) { - var mapKeysAsync; - var obj; - var i; - - mapKeysAsync = factory( fcn ); - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2a211e8..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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a `factory` method', function test( t ) { - t.strictEqual( typeof mapKeysAsync.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.main.js b/test/test.main.js deleted file mode 100644 index 8972c5d..0000000 --- a/test/test.main.js +++ /dev/null @@ -1,1039 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 mapKeysAsync = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapKeysAsync, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object (no options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided an object (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapKeysAsync( value, {}, next, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke for each own property in an object (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() { - mapKeysAsync( {}, {}, 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( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, next, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a callback function (options)', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [] - ]; - - for ( i = 0; i < values.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 obj = { - 'a': 1, - 'b': 2 - }; - mapKeysAsync( obj, {}, 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( key, clbk ) { - clbk( null, key ); - } - - 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() { - mapKeysAsync( {}, value, next, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - function next( key, clbk ) { - clbk( null, key ); - } - - 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 - }; - mapKeysAsync( {}, opts, next, noop ); - }; - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, next ) { - setTimeout( onTimeout, 0 ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function invokes a provided function once for each own property in an object (key,value,obj,next)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:1': 1, - 'b:2': 2, - 'c:3': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, o, next ) { - t.strictEqual( o, obj, 'provides input object' ); - setTimeout( onTimeout, value ); - function onTimeout() { - next( null, key+':'+value ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function accepts fewer than 2 arguments, the function invokes a provided function with four arguments (1 argument)', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key ) { - var next = arguments[ 3 ]; - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'if a provided function length is 0, the function invokes a provided function with four arguments', function test( t ) { - var expected; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - expected = { - 'a:beep': 1, - 'b:beep': 2, - 'c:beep': 3 - }; - - mapKeysAsync( obj, fcn, done ); - - function fcn() { - var next = arguments[ 3 ]; - var key = arguments[ 0 ]; - - t.strictEqual( arguments[ 2 ], obj, 'provides input object' ); - setTimeout( onTimeout, arguments[ 1 ] ); - - function onTimeout() { - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'by default, the function processes object properties concurrently', function test( t ) { - var expected; - var count; - var keys; - var obj; - - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'c', 'b', 'a' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (in series)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports processing object properties sequentially (limit = 1)', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 1 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'a', 'b', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports limiting the maximum number of object properties which are processed at any one time', function test( t ) { - var expected; - var count; - var keys; - var opts; - var obj; - - opts = { - 'series': false, - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 250, - 'c': 100 - }; - keys = [ 'b', 'a', 'c' ]; - expected = { - 'a:beep': 300, - 'b:beep': 250, - 'c:beep': 100 - }; - count = -1; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - setTimeout( onTimeout, value ); - - function onTimeout() { - count += 1; - t.strictEqual( key, keys[ count ], 'provides expected key' ); - next( null, key+':beep' ); - } - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); - } -}); - -tape( 'the function supports specifying an execution context for the invoked function', function test( t ) { - var opts; - var obj; - var ctx; - - ctx = { - 'count': 0 - }; - opts = { - 'thisArg': ctx - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - /* eslint-disable no-invalid-this */ - this.count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - next( null, value ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (series)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'series': true - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, 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 an object property, the function suspends execution and immediately returns the error (concurrent; limit)', function test( t ) { - var count; - var opts; - var obj; - - opts = { - 'limit': 2 - }; - obj = { - 'a': 300, - 'b': 100, - 'c': 250 - }; - count = 0; - - mapKeysAsync( obj, opts, fcn, done ); - - function fcn( key, value, next ) { - count += 1; - setTimeout( onTimeout, value ); - - function onTimeout() { - return next( new Error( 'beep' ) ); - } - } - - 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 an object property, the function suspends execution and immediately returns the error (concurrent)', function test( t ) { - var count; - var obj; - - obj = { - 'a': 500, - 'b': 500, - 'c': 500 - }; - count = 0; - mapKeysAsync( obj, fcn, done ); - - function fcn( key, value, 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( 'the function ignores inherited properties', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - if ( key === 'f' || key === 'g' ) { - t.ok( false, 'returns an inherited property' ); - } - return next( null, key ); - } - - function Foo() { - this.a = 1; - this.b = 2; - this.c = 3; - this.d = 4; - this.e = 5; - return this; - } - - Foo.prototype.f = 6; - Foo.prototype.g = 7; - - obj1 = new Foo(); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4, - 'e': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function accepts non-plain objects', function test( t ) { - var expected; - var obj1; - - function fcn( key, value, next ) { - return next( null, key + value ); - } - - obj1 = [ 0, 1, 2, 3, 4, 5 ]; - - expected = { - '00': 0, - '11': 1, - '22': 2, - '33': 3, - '44': 4, - '55': 5 - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.end(); - } -}); - -tape( 'the function returns a shallow copy', function test( t ) { - var expected; - var obj1; - - function fcn( key, next ) { - return next( null, key ); - } - - obj1 = { - 'a': [ 1 ], - 'b': [ 2 ], - 'c': [ 3 ], - 'd': [ 4 ], - 'e': [ 5 ] - }; - - expected = { - 'a': obj1.a, - 'b': obj1.b, - 'c': obj1.c, - 'd': obj1.d, - 'e': obj1.e - }; - - mapKeysAsync( obj1, fcn, done ); - - function done( error, obj2 ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.deepEqual( obj2, expected, 'returns expected object' ); - t.strictEqual( obj2.a, obj1.a, 'returns shallow copy' ); - t.strictEqual( obj2.b, obj1.b, 'returns shallow copy' ); - t.strictEqual( obj2.c, obj1.c, 'returns shallow copy' ); - t.strictEqual( obj2.d, obj1.d, 'returns shallow copy' ); - t.strictEqual( obj2.e, obj1.e, 'returns shallow copy' ); - - t.end(); - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - mapKeysAsync( obj, fcn, done ); - - function fcn() { - t.fail( 'should never be called' ); - } - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, {}, 'returns an empty object' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next( null, value ); - } - - obj = { - 'a': {} - }; - expected = { - '[object Object]': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function serializes transform function return values as object keys', function test( t ) { - var expected; - var obj; - - function fcn( key, value, next ) { - return next(); - } - - obj = { - 'a': 1 - }; - expected = { - 'undefined': obj.a - }; - - mapKeysAsync( obj, fcn, done ); - - function done( error, out ) { - if ( error ) { - t.fail( error.message ); - } else { - t.pass( 'did not return an error' ); - } - t.notEqual( out, obj, 'returns a new object' ); - t.deepEqual( out, expected, 'returns expected output' ); - t.end(); - } -}); - -tape( 'the function does not guarantee asynchronous execution', function test( t ) { - var obj; - var i; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - i = 0; - - mapKeysAsync( obj, fcn, done ); - i = 1; - - function fcn( key, next ) { - next( null, key ); - } - - 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(); - } -}); 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(); -});