From c5ba505bc6ba7e81bf36cebae13907dd4443b065 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 09:31:43 +0000 Subject: [PATCH 001/105] Auto-generated commit d686cee13f80598772f4fae5ec617cb07667808f --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 327 ++++++ index.d.ts | 100 ++ index.mjs | 4 + index.mjs.map | 1 + package.json | 39 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3670 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..467cdd0 --- /dev/null +++ b/README.md @@ -0,0 +1,327 @@ + + +# array2iterator + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Create an iterator from an array-like object. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; +``` + +#### array2iterator( src\[, mapFcn\[, thisArg]] ) + +Returns an iterator which iterates over each element in an array-like `object`. + +```javascript +var it = array2iterator( [ 1, 2, 3, 4 ] ); +// returns + +var v = it.next().value; +// returns 1 + +v = it.next().value; +// returns 2 + +v = it.next().value; +// returns 3 + +// ... +``` + +The returned iterator protocol-compliant object has the following properties: + +- **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished. +- **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. + +To invoke a function for each `src` value, provide a callback function. + +```javascript +function fcn( v ) { + return v * 10.0; +} + +var it = array2iterator( [ 1, 2, 3, 4 ], fcn ); +// returns + +var v = it.next().value; +// returns 10.0 + +v = it.next().value; +// returns 20.0 + +v = it.next().value; +// returns 30.0 + +// ... +``` + +The invoked function is provided three arguments: + +- **value**: iterated value. +- **index**: iterated value index. +- **src**: source array-like object. + +```javascript +function fcn( v, i ) { + return v * (i+1); +} + +var it = array2iterator( [ 1, 2, 3, 4 ], fcn ); +// returns + +var v = it.next().value; +// returns 1 + +v = it.next().value; +// returns 4 + +v = it.next().value; +// returns 9 + +// ... +``` + +To set the callback function execution context, provide a `thisArg`. + +```javascript +function fcn( v ) { + this.count += 1; + return v * 10.0; +} + +var ctx = { + 'count': 0 +}; + +var it = array2iterator( [ 1, 2, 3, 4 ], fcn, ctx ); +// returns + +var v = it.next().value; +// returns 10.0 + +v = it.next().value; +// returns 20.0 + +v = it.next().value; +// returns 30.0 + +var count = ctx.count; +// returns 3 +``` + + + + + + + +
+ +## Notes + +- If an environment supports `Symbol.iterator`, the returned iterator is iterable. +- If provided a generic `array`, the returned iterator does **not** ignore holes. To achieve greater performance for sparse arrays, use [`@stdlib/array/to-sparse-iterator`][@stdlib/array/to-sparse-iterator]. +- A returned iterator does **not** copy a provided array-like `object`. To ensure iterable reproducibility, copy a provided array-like `object` **before** creating an iterator. Otherwise, any changes to the contents of an array-like `object` will be reflected in the returned iterator. +- In environments supporting `Symbol.iterator`, the function **explicitly** does **not** invoke an array's `@@iterator` method, regardless of whether this method is defined. To convert an array to an implementation defined iterator, invoke this method directly. +- The returned iterator supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). + +
+ + + + + +
+ +## 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..982e7a9 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,100 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/// + +import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; +import { ArrayLike } from '@stdlib/types/array'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = Iter | IterableIterator; + +/** +* Map function invoked for each iterated value. +* +* @returns iterator value +*/ +type Nullary = () => any; + +/** +* Map function invoked for each iterated value. +* +* @param value - iterated value +* @returns iterator value +*/ +type Unary = ( value: any ) => any; + +/** +* Map function invoked for each iterated value. +* +* @param value - iterated value +* @param index - iterated value index +* @returns iterator value +*/ +type Binary = ( value: any, index: number ) => any; + +/** +* Map function invoked for each iterated value. +* +* @param value - iterated value +* @param index - iterated value index +* @param src - source array-like object +* @returns iterator value +*/ +type Ternary = ( value: any, index: number, src: ArrayLike ) => any; + +/** +* Map function invoked for each iterated value. +* +* @param value - iterated value +* @param index - iterated value index +* @param src - source array-like object +* @returns iterator value +*/ +type MapFunction = Nullary | Unary | Binary | Ternary; + +/** +* Returns an iterator which iterates over each element in an array-like object. +* +* @param src - input value +* @param mapFc - function to invoke for each iterated value +* @param thisArg - execution context +* @returns iterator +* +* @example +* var iter = array2iterator( [ 1, 2, 3, 4 ] ); +* +* var v = iter.next().value; +* // returns 1 +* +* v = iter.next().value; +* // returns 2 +* +* v = iter.next().value; +* // returns 3 +* +* // ... +*/ +declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length + + +// EXPORTS // + +export = array2iterator; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6d2fb37 --- /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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var o=e,d=t,l=n,m=r,a=s,u=i;var j=function e(t){var n,r,s,i,j,c;if(!l(t))throw new TypeError(u("invalid argument. First argument must be an array-like object. Value: `%s`.",t));if(arguments.length>1){if(!d(i=arguments[1]))throw new TypeError(u("invalid argument. Second argument must be a function. Value: `%s`.",i));n=arguments[2]}return c=-1,o(r={},"next",i?f:h),o(r,"return",p),m&&o(r,m,g),j=a(t).getter,r;function f(){return c+=1,s||c>=t.length?{done:!0}:{value:i.call(n,j(t,c),c,t),done:!1}}function h(){return c+=1,s||c>=t.length?{done:!0}:{value:j(t,c),done:!1}}function p(e){return s=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return i?e(t,i,n):e(t)}},c=j;export{c as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0e0053e --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar iterator = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = iterator;\n"],"names":["setReadOnly","require$$0","isFunction","require$$1","isCollection","require$$2","iteratorSymbol","require$$3","arraylike2object","require$$4","format","require$$5","main","array2iterator","src","thisArg","iter","FLG","fcn","get","i","TypeError","arguments","length","next1","next2","end","factory","getter","done","value","call","lib"],"mappings":";;kiBAsBA,IAAIA,EAAcC,EACdC,EAAaC,EACbC,EAAeC,EACfC,EAAiBC,EACjBC,EAAmBC,EACnBC,EAASC,EA6Ib,IAAAC,EAhHA,SAASC,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMhB,EAAcU,GACnB,MAAM,IAAIO,UAAWX,EAAQ,8EAA+EI,IAE7G,GAAKQ,UAAUC,OAAS,EAAI,CAE3B,IAAMrB,EADNgB,EAAMI,UAAW,IAEhB,MAAM,IAAID,UAAWX,EAAQ,qEAAsEQ,IAEpGH,EAAUO,UAAW,GAoBtB,OAlBAF,GAAK,EAKJpB,EAFDgB,EAAO,GAEa,OADfE,EACuBM,EAEAC,GAE5BzB,EAAagB,EAAM,SAAUU,GAGxBpB,GACJN,EAAagB,EAAMV,EAAgBqB,GAGpCR,EAAMX,EAAkBM,GAAMc,OAEvBZ,EAQP,SAASQ,IAER,OADAJ,GAAK,EACAH,GAAOG,GAAKN,EAAIS,OACb,CACNM,MAAQ,GAGH,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9Ce,MAAQ,GAUV,SAASJ,IAER,OADAL,GAAK,EACAH,GAAOG,GAAKN,EAAIS,OACb,CACNM,MAAQ,GAGH,CACNC,MAASX,EAAKL,EAAKM,GACnBS,MAAQ,GAWV,SAASH,EAAKI,GAEb,OADAb,GAAM,EACDK,UAAUC,OACP,CACNO,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASF,IACR,OAAKT,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,KChHzBkB,EALe/B"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..f191241 --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "@stdlib/array-to-iterator", + "version": "0.0.0", + "description": "Create an iterator from an array-like object.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/array-to-iterator.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdtypes", + "utils", + "util", + "utilities", + "utility", + "typed", + "array", + "arr", + "typed-array", + "typed array", + "iterator", + "iterate", + "iteration", + "iter", + "to", + "convert" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8fa9242 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 1a94d7e1a9524741c228c3fac568f5e32d68c562 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 23:09:42 +0000 Subject: [PATCH 002/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 7b70ebd..590019f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From a3a41736f62f2995dfe41d867a082f212b514813 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 10:32:06 +0000 Subject: [PATCH 003/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2794 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6d2fb37..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 n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var o=e,d=t,l=n,m=r,a=s,u=i;var j=function e(t){var n,r,s,i,j,c;if(!l(t))throw new TypeError(u("invalid argument. First argument must be an array-like object. Value: `%s`.",t));if(arguments.length>1){if(!d(i=arguments[1]))throw new TypeError(u("invalid argument. Second argument must be a function. Value: `%s`.",i));n=arguments[2]}return c=-1,o(r={},"next",i?f:h),o(r,"return",p),m&&o(r,m,g),j=a(t).getter,r;function f(){return c+=1,s||c>=t.length?{done:!0}:{value:i.call(n,j(t,c),c,t),done:!1}}function h(){return c+=1,s||c>=t.length?{done:!0}:{value:j(t,c),done:!1}}function p(e){return s=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return i?e(t,i,n):e(t)}},c=j;export{c as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0e0053e..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar iterator = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = iterator;\n"],"names":["setReadOnly","require$$0","isFunction","require$$1","isCollection","require$$2","iteratorSymbol","require$$3","arraylike2object","require$$4","format","require$$5","main","array2iterator","src","thisArg","iter","FLG","fcn","get","i","TypeError","arguments","length","next1","next2","end","factory","getter","done","value","call","lib"],"mappings":";;kiBAsBA,IAAIA,EAAcC,EACdC,EAAaC,EACbC,EAAeC,EACfC,EAAiBC,EACjBC,EAAmBC,EACnBC,EAASC,EA6Ib,IAAAC,EAhHA,SAASC,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMhB,EAAcU,GACnB,MAAM,IAAIO,UAAWX,EAAQ,8EAA+EI,IAE7G,GAAKQ,UAAUC,OAAS,EAAI,CAE3B,IAAMrB,EADNgB,EAAMI,UAAW,IAEhB,MAAM,IAAID,UAAWX,EAAQ,qEAAsEQ,IAEpGH,EAAUO,UAAW,GAoBtB,OAlBAF,GAAK,EAKJpB,EAFDgB,EAAO,GAEa,OADfE,EACuBM,EAEAC,GAE5BzB,EAAagB,EAAM,SAAUU,GAGxBpB,GACJN,EAAagB,EAAMV,EAAgBqB,GAGpCR,EAAMX,EAAkBM,GAAMc,OAEvBZ,EAQP,SAASQ,IAER,OADAJ,GAAK,EACAH,GAAOG,GAAKN,EAAIS,OACb,CACNM,MAAQ,GAGH,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9Ce,MAAQ,GAUV,SAASJ,IAER,OADAL,GAAK,EACAH,GAAOG,GAAKN,EAAIS,OACb,CACNM,MAAQ,GAGH,CACNC,MAASX,EAAKL,EAAKM,GACnBS,MAAQ,GAWV,SAASH,EAAKI,GAEb,OADAb,GAAM,EACDK,UAAUC,OACP,CACNO,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASF,IACR,OAAKT,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,KChHzBkB,EALe/B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8fa9242..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 6198d13b3ffa174ff0cfa2569a4fb0f8f9ca4d36 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 10:32:52 +0000 Subject: [PATCH 004/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 -- package.json | 68 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 616 ----- 37 files changed, 2719 insertions(+), 4106 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 12897cf..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:51:35.759Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cbea1f5..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - not invoke an array's `@@iterator` method, regardless of whether this method - is defined. To convert an array to an implementation defined iterator, - invoke this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..40b8f16 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9809df0 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;2iBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index af24353..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var iterator = require( './main.js' ); - - -// EXPORTS // - -module.exports = iterator; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 590019f..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0f51df8 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 7ecbb69572f71fa6cd019ffdab1a6b9a051dbbec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:43:19 +0000 Subject: [PATCH 005/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 7b70ebd..590019f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From 22a37c311eb9f306698bc1c9ec30c6440efedb66 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 06:38:44 +0000 Subject: [PATCH 006/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2794 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 40b8f16..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9809df0..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;2iBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0f51df8..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4542b6b4de09f5aaf9a9f6940a548e5f66ecd0be Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 06:39:33 +0000 Subject: [PATCH 007/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 -- package.json | 68 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 616 ----- 37 files changed, 2719 insertions(+), 4106 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 11bfb4f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:41:27.834Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cbea1f5..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - not invoke an array's `@@iterator` method, regardless of whether this method - is defined. To convert an array to an implementation defined iterator, - invoke this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..40b8f16 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9809df0 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;2iBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index af24353..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var iterator = require( './main.js' ); - - -// EXPORTS // - -module.exports = iterator; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 590019f..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..319ce67 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 211352fac964a0ff9ab0ce393fa64c2cce678c00 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:43:08 +0000 Subject: [PATCH 008/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 7b70ebd..590019f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From f75014d47983474283f8cdb7c589780f3efd47f4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:06:36 +0000 Subject: [PATCH 009/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2794 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 40b8f16..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9809df0..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;2iBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 319ce67..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 800b22d1bc417d1864539ef7b90b0bca96b33b89 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:07:18 +0000 Subject: [PATCH 010/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 -- package.json | 68 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 616 ----- 36 files changed, 2719 insertions(+), 4071 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cbea1f5..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - not invoke an array's `@@iterator` method, regardless of whether this method - is defined. To convert an array to an implementation defined iterator, - invoke this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..40b8f16 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9809df0 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;2iBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index af24353..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var iterator = require( './main.js' ); - - -// EXPORTS // - -module.exports = iterator; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 590019f..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..af9f050 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From abccb394bcf527445c46293fb23d64b7cef7fa36 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:57:15 +0000 Subject: [PATCH 011/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 7b70ebd..590019f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From 228f126373be655f54b2d3b308d65edea1f31a13 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:41:38 +0000 Subject: [PATCH 012/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2794 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 40b8f16..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9809df0..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;2iBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index af9f050..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 85567d5a2e289755090008227a77c75f47c30e1c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:42:17 +0000 Subject: [PATCH 013/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 -- package.json | 68 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 616 ----- 37 files changed, 2719 insertions(+), 4145 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 768becb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:43:38.795Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cbea1f5..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - not invoke an array's `@@iterator` method, regardless of whether this method - is defined. To convert an array to an implementation defined iterator, - invoke this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc3ac0b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..982a61a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index af24353..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var iterator = require( './main.js' ); - - -// EXPORTS // - -module.exports = iterator; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 590019f..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cb888fd --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 75570a5c114cac967d875aad9ad13e92a77106cf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 23 Aug 2022 19:22:28 +0000 Subject: [PATCH 014/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 7b70ebd..590019f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From e6752d974e5e60c03a185c0593f83c0f407fa027 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 23 Aug 2022 19:39:53 +0000 Subject: [PATCH 015/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2794 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc3ac0b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 982a61a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cb888fd..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a395d7ebd785eb1e350a3e47e3215ba6fe1dd6b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 23 Aug 2022 19:41:17 +0000 Subject: [PATCH 016/105] 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 | 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 -- package.json | 68 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 616 ----- 36 files changed, 2719 insertions(+), 4144 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc3ac0b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..982a61a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index af24353..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var iterator = require( './main.js' ); - - -// EXPORTS // - -module.exports = iterator; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 590019f..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9746c47 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 31087077740cb7f26ca2039572dc6859ebb30fbc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 04:21:26 +0000 Subject: [PATCH 017/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 7b70ebd..590019f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From 4756d9770942fc1ed1e0adf73fb0a0bcae867c81 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 18:36:37 +0000 Subject: [PATCH 018/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2794 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc3ac0b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 982a61a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9746c47..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 6991d64531f27c63502dcc8bf96b1bb73c048914 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 18:37:26 +0000 Subject: [PATCH 019/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 -- package.json | 68 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 616 ----- 37 files changed, 2719 insertions(+), 4161 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 1800aee..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:43:47.247Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc3ac0b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..982a61a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index af24353..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var iterator = require( './main.js' ); - - -// EXPORTS // - -module.exports = iterator; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 590019f..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2d86952 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From ad43ffc14e27293b0f9f84c0d10af293f6d976f2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:29:50 +0000 Subject: [PATCH 020/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 7b70ebd..590019f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From ceb391d67baf0da31dc10a737ee81992dfb29853 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 19:11:09 +0000 Subject: [PATCH 021/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2794 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc3ac0b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 982a61a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2d86952..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From af017f29b37a855edea27a2398d86210817e402a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 19:12:09 +0000 Subject: [PATCH 022/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 -- package.json | 68 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 616 ----- 37 files changed, 2719 insertions(+), 4161 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 7cd6fc5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:11:24.839Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc3ac0b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..982a61a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 590019f..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..81dda5c --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 7aa254a826520acd832879fef56f1f02abf0a8fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 02:13:15 +0000 Subject: [PATCH 023/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 7b70ebd..590019f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From 7406d84030532d134776949600f315c3af0c2082 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:32:41 +0000 Subject: [PATCH 024/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2794 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc3ac0b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 982a61a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,GAoBtB,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,GAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,GAUV,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,GAWV,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,GAUV,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 81dda5c..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a41edef38f8ec51b42c43becd2ab7d95ef6e6ef5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:33:37 +0000 Subject: [PATCH 025/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 - package.json | 68 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 616 ---- 37 files changed, 4074 insertions(+), 4161 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 ce6203b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:56:49.995Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 6c8cdca..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: '12 0 * * 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@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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc3ac0b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b7c4c36 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,EACrB,CAmBD,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,CAAA,EAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,EAET,CAQD,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,EAET,CASD,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 590019f..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6f3e0de --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From e0e4ca511444b7d0f6ad8c4f07ed73c436d93b41 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:41:50 +0000 Subject: [PATCH 026/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 7b70ebd..590019f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From bd1c6df73b273851080652c07122dc6dd491f3f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 08:52:25 +0000 Subject: [PATCH 027/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4149 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc3ac0b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index b7c4c36..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,EACrB,CAmBD,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,CAAA,EAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,EAET,CAQD,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,EAET,CASD,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6f3e0de..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 621cc53f5d44e0b8082297028aaefbc430f66f0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 08:53:21 +0000 Subject: [PATCH 028/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 - package.json | 68 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 616 ---- 37 files changed, 4074 insertions(+), 4182 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 8fa06d5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:58:22.311Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 6c8cdca..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: '12 0 * * 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@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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc3ac0b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..b7c4c36 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,EACrB,CAmBD,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,CAAA,EAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,EAET,CAQD,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,EAET,CASD,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 590019f..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fc10dbf --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 615b02075b1ff78959e6982f73cb2d666fe76160 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:40:02 +0000 Subject: [PATCH 029/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index d274679..c53d267 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -62,12 +62,12 @@ function array2iterator( src ) { var get; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 9ffe0c3..36aa353 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@stdlib/array-base-arraylike2object": "^0.0.x", "@stdlib/assert-is-collection": "^0.0.x", "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/symbol-iterator": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" From bf62d60b1d83eeaf4749030155bbecac401fcec0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 18:45:14 +0000 Subject: [PATCH 030/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4149 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc3ac0b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index b7c4c36..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport isCollection from '@stdlib/assert-is-collection' ;\nimport iteratorSymbol from '@stdlib/symbol-iterator' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,EACrB,CAmBD,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,CAAA,EAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,EAET,CAQD,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,EAET,CASD,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fc10dbf..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From bf3a18776723d557169387c37a72e93d09e3fc86 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 18:46:02 +0000 Subject: [PATCH 031/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 169 - package.json | 68 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 616 ---- 37 files changed, 4074 insertions(+), 4187 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 4709864..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:46:59.841Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 6c8cdca..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: '12 0 * * 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@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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 7c4ee2b..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/array/to-iterator" -click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bc3ac0b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e47c47d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,EACrB,CAmBD,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,CAAA,EAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,EAET,CAQD,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,EAET,CASD,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c53d267..0000000 --- a/lib/main.js +++ /dev/null @@ -1,169 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - get = arraylike2object( src ).getter; - - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 36aa353..459ca82 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,47 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/symbol-iterator": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-iterator-like": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "@stdlib/utils-inmap": "^0.0.x", - "@stdlib/utils-noop": "^0.0.x", - "proxyquire": "^2.0.0", - "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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5ad7c0e --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3ffa827..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.equal( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 957caff01467525d9dc38dabb11c64aa75c66bfc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Jul 2023 16:25:47 +0000 Subject: [PATCH 032/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..66130fe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '00m2a', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '00m2S', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 3d59d7b..bde58ae 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.0.6", "@stdlib/assert-is-collection": "^0.0.8", "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/symbol-iterator": "^0.0.7", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" From c6bdb1a4d5b6b87d0dc0e3f671a891cd590dbabd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Jul 2023 16:52:18 +0000 Subject: [PATCH 033/105] Remove files --- index.d.ts | 100 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4149 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bc3ac0b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function i(d){var l,m,j,a,f,h;if(!r(d))throw new TypeError(o("00m2a",d));if(arguments.length>1){if(!t(a=arguments[1]))throw new TypeError(o("00m2S",a));l=arguments[2]}return h=-1,e(m={},"next",a?p:u),e(m,"return",c),n&&e(m,n,g),f=s(d).getter,m;function p(){return h+=1,j||h>=d.length?{done:!0}:{value:a.call(l,f(d,h),h,d),done:!1}}function u(){return h+=1,j||h>=d.length?{done:!0}:{value:f(d,h),done:!1}}function c(e){return j=!0,arguments.length?{value:e,done:!0}:{done:!0}}function g(){return a?i(d,a,l):i(d)}}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e47c47d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tget = arraylike2object( src ).getter;\n\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","arraylike2object","getter","done","value","call"],"mappings":";;kjBAwDA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcP,GACnB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNR,EAAMM,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASL,IAEvCH,EAAUS,UAAW,EACrB,CAmBD,OAlBAJ,GAAK,EAKJO,EAFDX,EAAO,CAAA,EAEa,OADfE,EACuBU,EAEAC,GAE5BF,EAAaX,EAAM,SAAUc,GAGxBC,GACJJ,EAAaX,EAAMe,EAAgBC,GAGpCb,EAAMc,EAAkBnB,GAAMoB,OAEvBlB,EAQP,SAASY,IAER,OADAR,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASlB,EAAImB,KAAMtB,EAASI,EAAKL,EAAKM,GAAKA,EAAGN,GAC9CqB,MAAQ,EAET,CAQD,SAASN,IAER,OADAT,GAAK,EACAH,GAAOG,GAAKN,EAAIW,OACb,CACNU,MAAQ,GAGH,CACNC,MAASjB,EAAKL,EAAKM,GACnBe,MAAQ,EAET,CASD,SAASL,EAAKM,GAEb,OADAnB,GAAM,EACDO,UAAUC,OACP,CACNW,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASH,IACR,OAAKd,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5ad7c0e..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 27a9dcc7c227635329c7940e83f66917c669312d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Jul 2023 16:53:18 +0000 Subject: [PATCH 034/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 616 -- 36 files changed, 6207 insertions(+), 4349 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 6c8cdca..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: '12 0 * * 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@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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd90bb6..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index aebeaae..982e7a9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..993c60a --- /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/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.0.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.0.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function l(a){var j,p,h,c,f,u,g;if(!r(a))throw new TypeError(m("00m2a",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("00m2S",c));j=arguments[2]}return g=-1,e(p={},"next",c?v:b),e(p,"return",x),n&&e(p,n,y),u=d(a),f=s(a)?i(u):o(u),p;function v(){return g+=1,h||g>=a.length?{done:!0}:{value:c.call(j,f(a,g),g,a),done:!1}}function b(){return g+=1,h||g>=a.length?{done:!0}:{value:f(a,g),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..65eda85 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;00BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 66130fe..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '00m2a', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '00m2S', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index bde58ae..9290475 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.0.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.0.1", - "@stdlib/array-base-getter": "^0.0.1", - "@stdlib/array-dtype": "^0.0.6", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/symbol-iterator": "^0.0.7", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-iterator-like": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/complex-float32": "^0.0.7", - "@stdlib/complex-imagf": "^0.0.1", - "@stdlib/complex-realf": "^0.0.1", - "@stdlib/math-base-assert-is-nan": "^0.0.8", - "@stdlib/random-base-randu": "^0.0.8", - "@stdlib/utils-inmap": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "proxyquire": "^2.0.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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..565596c --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From a184de95974ea94ee22279da7442ff75822c7486 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:50:15 +0000 Subject: [PATCH 035/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..822df70 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O,GW', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H,G6', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 3d59d7b..bde58ae 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.0.6", "@stdlib/assert-is-collection": "^0.0.8", "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/symbol-iterator": "^0.0.7", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" From 20b6e91f8392f7bf2780ad36804c158ce46e0741 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:56:01 +0000 Subject: [PATCH 036/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 982e7a9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 993c60a..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/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.0.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.0.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function l(a){var j,p,h,c,f,u,g;if(!r(a))throw new TypeError(m("00m2a",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("00m2S",c));j=arguments[2]}return g=-1,e(p={},"next",c?v:b),e(p,"return",x),n&&e(p,n,y),u=d(a),f=s(a)?i(u):o(u),p;function v(){return g+=1,h||g>=a.length?{done:!0}:{value:c.call(j,f(a,g),g,a),done:!1}}function b(){return g+=1,h||g>=a.length?{done:!0}:{value:f(a,g),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 65eda85..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '00m2a', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '00m2S', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;00BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 565596c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From eea574012cc4a71e500f30d12529df152b631677 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:57:09 +0000 Subject: [PATCH 037/105] 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 | 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 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 616 -- 39 files changed, 6207 insertions(+), 4349 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 6c8cdca..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: '12 0 * * 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@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 + + ```
@@ -254,7 +247,7 @@ while ( true ) { ## 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]. @@ -314,19 +307,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd90bb6..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index a17a346..162b068 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d83a220 --- /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/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.0.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.0.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function l(a){var j,p,h,c,f,u,g;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return g=-1,e(p={},"next",c?v:b),e(p,"return",x),n&&e(p,n,y),u=d(a),f=s(a)?i(u):o(u),p;function v(){return g+=1,h||g>=a.length?{done:!0}:{value:c.call(j,f(a,g),g,a),done:!1}}function b(){return g+=1,h||g>=a.length?{done:!0}:{value:f(a,g),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..cdf71aa --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;00BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 822df70..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O,GW', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H,G6', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index bde58ae..9290475 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.0.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.0.1", - "@stdlib/array-base-getter": "^0.0.1", - "@stdlib/array-dtype": "^0.0.6", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/symbol-iterator": "^0.0.7", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-iterator-like": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/complex-float32": "^0.0.7", - "@stdlib/complex-imagf": "^0.0.1", - "@stdlib/complex-realf": "^0.0.1", - "@stdlib/math-base-assert-is-nan": "^0.0.8", - "@stdlib/random-base-randu": "^0.0.8", - "@stdlib/utils-inmap": "^0.0.8", - "@stdlib/utils-noop": "^0.0.14", - "proxyquire": "^2.0.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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0828732 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From cb8e5ca1085f00ef47c0b00a4c8692e1d1050767 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 16:59:43 +0000 Subject: [PATCH 038/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..822df70 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O,GW', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H,G6', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index ac11f38..d9fa2d3 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.1.0", "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/symbol-iterator": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" From b09d678630e603815ac0e1ff79cf00731e42d0d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 17:28:33 +0000 Subject: [PATCH 039/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 162b068..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d83a220..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/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.0.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.0.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function l(a){var j,p,h,c,f,u,g;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return g=-1,e(p={},"next",c?v:b),e(p,"return",x),n&&e(p,n,y),u=d(a),f=s(a)?i(u):o(u),p;function v(){return g+=1,h||g>=a.length?{done:!0}:{value:c.call(j,f(a,g),g,a),done:!1}}function b(){return g+=1,h||g>=a.length?{done:!0}:{value:f(a,g),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index cdf71aa..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;00BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0828732..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5b9f52e98bdaa781a00f50afb37bd3c089054406 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 17:30:33 +0000 Subject: [PATCH 040/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 616 -- 40 files changed, 6207 insertions(+), 4384 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 bee72d2..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/array/to-iterator) 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 6c8cdca..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: '12 0 * * 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@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 + + ```
@@ -265,7 +258,7 @@ while ( true ) { ## 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]. @@ -325,19 +318,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd90bb6..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index a17a346..162b068 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..67ff66c --- /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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function l(a){var j,p,h,c,f,v,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),v=d(a),f=s(a)?i(v):o(v),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,f(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:f(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d515d6b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;62BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 822df70..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O,GW', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H,G6', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index d9fa2d3..b56af6d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/symbol-iterator": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-imagf": "^0.1.0", - "@stdlib/complex-realf": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.0", - "@stdlib/random-base-randu": "^0.0.8", - "@stdlib/utils-inmap": "^0.1.0", - "@stdlib/utils-noop": "^0.1.0", - "proxyquire": "^2.0.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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..150b8a0 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 502b03d9ba96317910b8b7ba31d8d3b609598e4c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 17:43:22 +0000 Subject: [PATCH 041/105] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 824516f..fc7b85a 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.1.0-esm/index.mjs'; ``` #### array2iterator( src\[, mapFcn\[, thisArg]] ) @@ -193,7 +193,7 @@ var count = ctx.count; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; import inmap from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-inmap@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.1.0-esm/index.mjs'; function scale( v, i ) { return v * (i+1); From 5605edfa1ec6d63eea78a7ba6283b752e307a419 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 17:43:23 +0000 Subject: [PATCH 042/105] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc7b85a..9affead 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@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/array-to-iterator/tags). For example, + ```javascript import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.1.0-esm/index.mjs'; ``` @@ -193,7 +198,7 @@ var count = ctx.count; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; import inmap from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-inmap@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.1.0-esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; function scale( v, i ) { return v * (i+1); From ce71538d64c122ee8420bd04bf2e4d82e4a8a5f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 17:01:34 +0000 Subject: [PATCH 043/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..822df70 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O,GW', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H,G6', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 1b6c9a6..6ca7273 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.1.0", "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/symbol-iterator": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" From b6c3489b7d3fc9a69125473968cd924a3c895d83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 02:29:21 +0000 Subject: [PATCH 044/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 162b068..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 67ff66c..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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function l(a){var j,p,h,c,f,v,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),v=d(a),f=s(a)?i(v):o(v),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,f(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:f(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d515d6b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;62BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 150b8a0..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1822c13ec5ce58f12799f646ded77537b263138f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 02:32:26 +0000 Subject: [PATCH 045/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 616 -- test/test.js | 616 -- 42 files changed, 6207 insertions(+), 5059 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 61bdb30..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T05:28:28.786Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 781bdf1..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: '12 0 * * 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' - # 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 + + ```
@@ -265,7 +258,7 @@ while ( true ) { ## 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]. @@ -325,19 +318,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd90bb6..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index a17a346..162b068 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..60b3dc6 --- /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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..506e890 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 822df70..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O,GW', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H,G6', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 6ca7273..b56af6d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/symbol-iterator": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-imagf": "^0.1.0", - "@stdlib/complex-realf": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/utils-inmap": "^0.1.0", - "@stdlib/utils-noop": "^0.1.0", - "proxyquire": "^2.0.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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6500a64 --- /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 0ce8c1d..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../dist/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../dist/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../dist/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../dist/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 803d7fe1a8194585744ed22df938c3cb5a166a8e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 20:06:50 +0000 Subject: [PATCH 046/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..822df70 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O,GW', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H,G6', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 0b45516..80219ad 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.1.0", "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 8d191da73ecefab868cb24d754223e878c718db8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 03:30:25 +0000 Subject: [PATCH 047/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 162b068..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 60b3dc6..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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 506e890..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6500a64..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c5ff868ff750040e5cf5e4c51b89f8c7f2e29bac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 03:34:04 +0000 Subject: [PATCH 048/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 41 files changed, 6207 insertions(+), 4475 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 781bdf1..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: '12 0 * * 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' - # 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 + + ```
@@ -265,7 +258,7 @@ while ( true ) { ## 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]. @@ -325,19 +318,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd90bb6..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index a17a346..162b068 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..368417a --- /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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..506e890 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 822df70..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O,GW', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H,G6', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 80219ad..b56af6d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-imagf": "^0.1.0", - "@stdlib/complex-realf": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/utils-inmap": "^0.1.0", - "@stdlib/utils-noop": "^0.1.1", - "proxyquire": "^2.0.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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6a263c2 --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 81a436abc6977abaa31d43e3bc44911ae20ac5ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 17:50:37 +0000 Subject: [PATCH 049/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..822df70 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O,GW', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H,G6', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 116bfb5..f80421f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.1.0", "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 5a084aa47741ecb12720581580b955414347ff07 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 02:25:48 +0000 Subject: [PATCH 050/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 162b068..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 368417a..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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 506e890..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6a263c2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 15fdc1699a6008ffedf2ef4135090531cfb4758b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 02:28:39 +0000 Subject: [PATCH 051/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 42 files changed, 6207 insertions(+), 4484 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 c6efc3a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:48:28.345Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 781bdf1..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: '12 0 * * 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' - # 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 + + ```
@@ -265,7 +258,7 @@ while ( true ) { ## 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]. @@ -325,19 +318,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd90bb6..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index a17a346..162b068 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dbae2c6 --- /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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..506e890 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 822df70..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O,GW', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H,G6', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index f80421f..b56af6d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/utils-inmap": "^0.1.0", - "@stdlib/utils-noop": "^0.1.1", - "proxyquire": "^2.0.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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d776044 --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From d52420dbf5d01f2327a82cff586592885b47290e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 12:56:19 +0000 Subject: [PATCH 052/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..822df70 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O,GW', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H,G6', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 116bfb5..f80421f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.1.0", "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From d9b3abcdd96a40e745029d1e5107adc5f7c06794 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 17:31:02 +0000 Subject: [PATCH 053/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 162b068..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dbae2c6..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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 506e890..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d776044..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From db7649e0c2095cf6df3f63736a8dc69b46ee7c9a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 17:33:30 +0000 Subject: [PATCH 054/105] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 41 files changed, 6207 insertions(+), 4483 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 781bdf1..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: '12 0 * * 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' - # 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 + + ```
@@ -265,7 +258,7 @@ while ( true ) { ## 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]. @@ -325,19 +318,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd90bb6..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dbae2c6 --- /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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..506e890 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 822df70..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O,GW', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H,G6', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index f80421f..b56af6d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/utils-inmap": "^0.1.0", - "@stdlib/utils-noop": "^0.1.1", - "proxyquire": "^2.0.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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7806e5c --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 3802925a6fc2380147937bc826e037c0fdef5ab0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:57:34 +0000 Subject: [PATCH 055/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..822df70 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O,GW', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H,G6', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 3c5b7ec..838e718 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.1.0", "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 564319f9f252e0686cd4a23a352541f22293939e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:06:25 +0000 Subject: [PATCH 056/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dbae2c6..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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 506e890..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7806e5c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1d5e9916a2ae02354bb15f89169cdbea8b7005e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:09:10 +0000 Subject: [PATCH 057/105] 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 | 51 +- benchmark/benchmark.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 42 files changed, 6207 insertions(+), 4479 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 4856e0f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T05:52:58.465Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 781bdf1..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: '12 0 * * 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' - # 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 + + ```
@@ -265,7 +258,7 @@ while ( true ) { ## 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]. @@ -325,19 +318,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2dfecdf..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd90bb6..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dbae2c6 --- /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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..506e890 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 822df70..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O,GW', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H,G6', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 838e718..b56af6d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/utils-inmap": "^0.1.0", - "@stdlib/utils-noop": "^0.1.1", - "proxyquire": "^2.0.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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2a73a84 --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From f012e9b673a769039a791edc09de155ff91660b9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:18:18 +0000 Subject: [PATCH 058/105] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9818b4b..6798ef1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.1.0", "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 0890b184d3d759eecc4101eef78472618bc3775e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:54:42 +0000 Subject: [PATCH 059/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dbae2c6..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/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function l(a){var j,p,h,c,v,f,u;if(!r(a))throw new TypeError(m("01Z2O,GW",a));if(arguments.length>1){if(!t(c=arguments[1]))throw new TypeError(m("01Z2H,G6",c));j=arguments[2]}return u=-1,e(p={},"next",c?g:b),e(p,"return",x),n&&e(p,n,y),f=d(a),v=s(a)?i(f):o(f),p;function g(){return u+=1,h||u>=a.length?{done:!0}:{value:c.call(j,v(a,u),u,a),done:!1}}function b(){return u+=1,h||u>=a.length?{done:!0}:{value:v(a,u),done:!1}}function x(e){return h=!0,arguments.length?{value:e,done:!0}:{done:!0}}function y(){return c?l(a,c,j):l(a)}}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 506e890..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O,GW', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H,G6', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,WAAYV,IAE1C,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,WAAYN,IAE1CH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2a73a84..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1abcd56b2c328a268c8f8d3f73dfda864e939d13 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:55:07 +0000 Subject: [PATCH 060/105] 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 | 51 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 43 files changed, 6207 insertions(+), 4485 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 9b7bfd5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:21:50.985Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 808906c..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: '12 0 * * 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' - # 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 + + ```
@@ -265,7 +258,7 @@ while ( true ) { ## 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]. @@ -325,19 +318,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd90bb6..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[esm-url]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dc80c45 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(l){var j,u,c,h,p,v,f;if(!r(l))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",l));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("invalid argument. Second argument must be a function. Value: `%s`.",h));j=arguments[2]}return f=-1,e(u={},"next",h?g:b),e(u,"return",y),n&&e(u,n,x),v=o(l),p=s(l)?i(v):d(v),u;function g(){return f+=1,c||f>=l.length?{done:!0}:{value:h.call(j,p(l,f),f,l),done:!1}}function b(){return f+=1,c||f>=l.length?{done:!0}:{value:p(l,f),done:!1}}function y(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function x(){return h?a(l,h,j):a(l)}}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..78b02f2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;22BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,8EAA+EV,IAE7G,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,qEAAsEN,IAEpGH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2df0ea0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 6798ef1..b56af6d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/utils-inmap": "^0.1.0", - "@stdlib/utils-noop": "^0.1.1", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d4cd816 --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From f826a4975b471922a9c97e006740f9e700c1a7c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:52:19 +0000 Subject: [PATCH 061/105] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9818b4b..6798ef1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.1.0", "@stdlib/assert-is-collection": "^0.1.0", "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/symbol-iterator": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 5edf5c265985b1f6a5bfddddbdef873e57c3ba57 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:13:34 +0000 Subject: [PATCH 062/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dc80c45..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(l){var j,u,c,h,p,v,f;if(!r(l))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",l));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("invalid argument. Second argument must be a function. Value: `%s`.",h));j=arguments[2]}return f=-1,e(u={},"next",h?g:b),e(u,"return",y),n&&e(u,n,x),v=o(l),p=s(l)?i(v):d(v),u;function g(){return f+=1,c||f>=l.length?{done:!0}:{value:h.call(j,p(l,f),f,l),done:!1}}function b(){return f+=1,c||f>=l.length?{done:!0}:{value:p(l,f),done:!1}}function y(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function x(){return h?a(l,h,j):a(l)}}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 78b02f2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;22BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,8EAA+EV,IAE7G,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,qEAAsEN,IAEpGH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d4cd816..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b4491a04de0201a23a2522e9efd723a013b91652 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:14:01 +0000 Subject: [PATCH 063/105] 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 | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 43 files changed, 6207 insertions(+), 4490 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 c5bec18..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T06:13:12.610Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 808906c..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dc80c45 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(l){var j,u,c,h,p,v,f;if(!r(l))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",l));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("invalid argument. Second argument must be a function. Value: `%s`.",h));j=arguments[2]}return f=-1,e(u={},"next",h?g:b),e(u,"return",y),n&&e(u,n,x),v=o(l),p=s(l)?i(v):d(v),u;function g(){return f+=1,c||f>=l.length?{done:!0}:{value:h.call(j,p(l,f),f,l),done:!1}}function b(){return f+=1,c||f>=l.length?{done:!0}:{value:p(l,f),done:!1}}function y(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function x(){return h?a(l,h,j):a(l)}}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..78b02f2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;22BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,8EAA+EV,IAE7G,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,qEAAsEN,IAEpGH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2df0ea0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 6798ef1..b56af6d 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.1.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.1.0", - "@stdlib/array-base-getter": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/symbol-iterator": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-iterator-like": "^0.1.1", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/utils-inmap": "^0.1.0", - "@stdlib/utils-noop": "^0.1.1", - "proxyquire": "^2.0.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c662d87 --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 27170c57e9ff62d18596d6102944c87f5533086d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 00:54:24 +0000 Subject: [PATCH 064/105] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 81c70d0..b7cc8ff 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.2.0", "@stdlib/assert-is-collection": "^0.2.0", "@stdlib/assert-is-function": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/symbol-iterator": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" From 88e142020a4d198871ae16a449f6d080f1964638 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:09:42 +0000 Subject: [PATCH 065/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dc80c45..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(l){var j,u,c,h,p,v,f;if(!r(l))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",l));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("invalid argument. Second argument must be a function. Value: `%s`.",h));j=arguments[2]}return f=-1,e(u={},"next",h?g:b),e(u,"return",y),n&&e(u,n,x),v=o(l),p=s(l)?i(v):d(v),u;function g(){return f+=1,c||f>=l.length?{done:!0}:{value:h.call(j,p(l,f),f,l),done:!1}}function b(){return f+=1,c||f>=l.length?{done:!0}:{value:p(l,f),done:!1}}function y(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function x(){return h?a(l,h,j):a(l)}}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 78b02f2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;22BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,8EAA+EV,IAE7G,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,qEAAsEN,IAEpGH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c662d87..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1e87936eb455258a121a63439c729a961b46ab2e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:10:55 +0000 Subject: [PATCH 066/105] 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 | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 71 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 -- 42 files changed, 6207 insertions(+), 4493 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 c559180..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3e65daf --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(l){var j,u,c,h,p,v,f;if(!r(l))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",l));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("invalid argument. Second argument must be a function. Value: `%s`.",h));j=arguments[2]}return f=-1,e(u={},"next",h?g:b),e(u,"return",y),n&&e(u,n,x),v=o(l),p=s(l)?i(v):d(v),u;function g(){return f+=1,c||f>=l.length?{done:!0}:{value:h.call(j,p(l,f),f,l),done:!1}}function b(){return f+=1,c||f>=l.length?{done:!0}:{value:p(l,f),done:!1}}function y(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function x(){return h?a(l,h,j):a(l)}}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..78b02f2 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;22BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,8EAA+EV,IAE7G,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,qEAAsEN,IAEpGH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 2df0ea0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index b7cc8ff..019719b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Create an iterator from an array-like object.", "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,50 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.0", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.0", - "@stdlib/array-base-getter": "^0.2.0", - "@stdlib/array-dtype": "^0.2.0", - "@stdlib/assert-is-collection": "^0.2.0", - "@stdlib/assert-is-function": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/symbol-iterator": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float64": "^0.2.0", - "@stdlib/assert-is-iterator-like": "^0.2.0", - "@stdlib/complex-float32": "^0.2.0", - "@stdlib/complex-imagf": "^0.2.0", - "@stdlib/complex-realf": "^0.2.0", - "@stdlib/math-base-assert-is-nan": "^0.2.0", - "@stdlib/random-base-randu": "^0.1.0", - "@stdlib/utils-inmap": "^0.2.0", - "@stdlib/utils-noop": "^0.2.0", - "proxyquire": "^2.0.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", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ff9b742 --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 8fcaac06cce951d853ec04ad4cf2926da6a92d1f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:05:23 +0000 Subject: [PATCH 067/105] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5a06744..006cbdd 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.0-esm/index.mjs'; ``` #### array2iterator( src\[, mapFcn\[, thisArg]] ) @@ -193,7 +193,7 @@ var count = ctx.count; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; import inmap from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-inmap@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.0-esm/index.mjs'; function scale( v, i ) { return v * (i+1); From d1ad2cb607670d840665b8121a35ba25ef4c6a34 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:05:24 +0000 Subject: [PATCH 068/105] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 006cbdd..06c778e 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@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/array-to-iterator/tags). For example, + ```javascript import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.0-esm/index.mjs'; ``` @@ -193,7 +198,7 @@ var count = ctx.count; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; import inmap from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-inmap@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.0-esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; function scale( v, i ) { return v * (i+1); From 4349950a260dd1417ae1cef8152fdce4c5757bc0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:39:17 +0000 Subject: [PATCH 069/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index a9c36aa..11b2370 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.2.1", "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From e845cfef3e82b04cad5871aa3221be5ad906842b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:46:35 +0000 Subject: [PATCH 070/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6282 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3e65daf..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function a(l){var j,u,c,h,p,v,f;if(!r(l))throw new TypeError(m("invalid argument. First argument must be an array-like object. Value: `%s`.",l));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("invalid argument. Second argument must be a function. Value: `%s`.",h));j=arguments[2]}return f=-1,e(u={},"next",h?g:b),e(u,"return",y),n&&e(u,n,x),v=o(l),p=s(l)?i(v):d(v),u;function g(){return f+=1,c||f>=l.length?{done:!0}:{value:h.call(j,p(l,f),f,l),done:!1}}function b(){return f+=1,c||f>=l.length?{done:!0}:{value:p(l,f),done:!1}}function y(e){return c=!0,arguments.length?{value:e,done:!0}:{done:!0}}function x(){return h?a(l,h,j):a(l)}}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 78b02f2..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","next1","next2","end","iteratorSymbol","factory","dtype","isAccessorArray","accessorGetter","getter","done","value","call"],"mappings":";;22BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,8EAA+EV,IAE7G,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,qEAAsEN,IAEpGH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EACuBW,EAEAC,GAE5BF,EAAaZ,EAAM,SAAUe,GAGxBC,GACJJ,EAAaZ,EAAMgB,EAAgBC,GAGpCb,EAAKc,EAAOpB,GAEXK,EADIgB,EAAiBrB,GACfsB,EAAgBhB,GAEhBiB,EAAQjB,GAERJ,EAQP,SAASa,IAER,OADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASrB,EAAIsB,KAAMzB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9CwB,MAAQ,EAET,CAQD,SAASR,IAER,OADAT,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACb,CACNY,MAAQ,GAGH,CACNC,MAASpB,EAAKL,EAAKO,GACnBiB,MAAQ,EAET,CASD,SAASP,EAAKQ,GAEb,OADAtB,GAAM,EACDQ,UAAUC,OACP,CACNa,MAASA,EACTD,MAAQ,GAGH,CACNA,MAAQ,EAET,CAQD,SAASL,IACR,OAAKf,EACGL,EAAgBC,EAAKI,EAAKH,GAE3BF,EAAgBC,EACvB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ff9b742..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 18e843ce714d15a6d67e8286af00191dc08a14db Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:46:55 +0000 Subject: [PATCH 071/105] 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 | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4872 insertions(+), 4488 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..01aea52 --- /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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 11b2370..9ca69d2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.2.0", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.0", - "@stdlib/utils-inmap": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "proxyquire": "^2.0.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.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a1eb7e9 --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 5cf153f791de3e5b364deaabf7440d3036e9a2fc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:29:00 +0000 Subject: [PATCH 072/105] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f2a8d9f..237c901 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.1-esm/index.mjs'; ``` #### array2iterator( src\[, mapFcn\[, thisArg]] ) @@ -193,7 +193,7 @@ var count = ctx.count; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; import inmap from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-inmap@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.1-esm/index.mjs'; function scale( v, i ) { return v * (i+1); From 2ee9345496834f01a1cc5e44ae65c5cd9eab18b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:29:01 +0000 Subject: [PATCH 073/105] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 237c901..e8b20d7 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@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/array-to-iterator/tags). For example, + ```javascript import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.1-esm/index.mjs'; ``` @@ -193,7 +198,7 @@ var count = ctx.count; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; import inmap from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-inmap@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.1-esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; function scale( v, i ) { return v * (i+1); From 41f46dd99823743028c4f2697dd9be209890da85 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 08:09:06 +0000 Subject: [PATCH 074/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 6f7ed10..e28dec7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.2.1", "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From d40f8a1b259ceb12de7534c89c77dda1772ca0b1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:53:00 +0000 Subject: [PATCH 075/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 01aea52..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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a1eb7e9..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From dad565cc644d24b8d57c33879b3f11c9102335f4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:53:21 +0000 Subject: [PATCH 076/105] 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 | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4872 insertions(+), 4490 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 b8651bc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:53:31.985Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d284cb5 --- /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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index e28dec7..9ca69d2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "proxyquire": "^2.0.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.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9fd6a8f --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From f3d6914fb06e589aacc5a1ae556cd9edd512eb07 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:27:45 +0000 Subject: [PATCH 077/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 6f7ed10..e28dec7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.2.1", "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From ab200a70d71f456bf703a15b4125256786db3f00 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:51:56 +0000 Subject: [PATCH 078/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d284cb5..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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9fd6a8f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 227af4ec81a25aa846c8690ea17693d30960713e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:52:14 +0000 Subject: [PATCH 079/105] 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 | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4872 insertions(+), 4493 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 81709a0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:10:39.041Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d284cb5 --- /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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index e28dec7..9ca69d2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "proxyquire": "^2.0.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.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9fd6a8f --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 88ec4f0867f76bf1f6ac07cff32346a24e06c374 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:42:31 +0000 Subject: [PATCH 080/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 6f7ed10..e28dec7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.2.1", "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From bb37d899495174dbed68b6bfc3570c644d2d4cec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:02:56 +0000 Subject: [PATCH 081/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d284cb5..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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9fd6a8f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d025341b4a71e78edda83eb7a6e06e071fe5ad85 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:03:09 +0000 Subject: [PATCH 082/105] 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 | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4872 insertions(+), 4494 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d284cb5 --- /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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index e28dec7..9ca69d2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "proxyquire": "^2.0.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.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9fd6a8f --- /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.js b/test/test.js deleted file mode 100644 index c19d101..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From ad173a9183da14d357120def9031ebdd7a6b1576 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 May 2024 08:56:17 +0000 Subject: [PATCH 083/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index f5229fe..6511dc2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.2.1", "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From d0f2488cdf5f16260996cc9947a2a0ec90ea29e1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 May 2024 08:58:47 +0000 Subject: [PATCH 084/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d284cb5..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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9fd6a8f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f7aed65d00d2e6d7d51230007f0c6348bb2948eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 May 2024 08:59:04 +0000 Subject: [PATCH 085/105] 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 | 248 -- .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 | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4872 insertions(+), 4501 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 f92a6c5..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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d284cb5 --- /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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index 6511dc2..9ca69d2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/complex-float32-ctor": "github:stdlib-js/complex-float32-ctor#main", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "proxyquire": "^2.0.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.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9fd6a8f --- /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.js b/test/test.js deleted file mode 100644 index 59092f7..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From a83e16814bfe7555cec1fb33e7d50b0429583eb0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Jul 2024 03:32:09 +0000 Subject: [PATCH 086/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 8be5202..cc350ce 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.2.1", "@stdlib/assert-is-collection": "^0.2.1", "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/symbol-iterator": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 21b4b9a92cc96181b02468936d6f8d3a80ec57fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Jul 2024 03:42:12 +0000 Subject: [PATCH 087/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d284cb5..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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9fd6a8f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2b7603d57932d9e2c6a3cb22e4097343c77fc742 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Jul 2024 03:42:34 +0000 Subject: [PATCH 088/105] 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 | 99 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4872 insertions(+), 4599 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 f92a6c5..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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d284cb5 --- /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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index cc350ce..9ca69d2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.1", - "@stdlib/array-base-getter": "^0.2.1", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/symbol-iterator": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-iterator-like": "^0.2.1", - "@stdlib/complex-float32-ctor": "^0.0.1", - "@stdlib/complex-float32-imag": "github:stdlib-js/complex-float32-imag#main", - "@stdlib/complex-float32-real": "github:stdlib-js/complex-float32-real#main", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.1", - "@stdlib/utils-noop": "^0.2.1", - "proxyquire": "^2.0.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.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9fd6a8f --- /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.js b/test/test.js deleted file mode 100644 index 65a4c72..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 59b1d645f61f81233312f5323bf6a9d56403e3d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:08:50 +0000 Subject: [PATCH 089/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 40464a1..dec104d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.2.1", "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 4c971fb8173dc1d84081913e1f6da0a0ff72ea91 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:35:32 +0000 Subject: [PATCH 090/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d284cb5..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/assert-is-collection@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9fd6a8f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2ffb529d6c3af1696b574b8ac365b754bc93ba3c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:35:49 +0000 Subject: [PATCH 091/105] 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 | 202 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4872 insertions(+), 4704 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..af4c78b --- /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/assert-is-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index dec104d..e14cd15 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.1", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..56be9ca --- /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.js b/test/test.js deleted file mode 100644 index 65a4c72..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 2bdf94a0d160c3989949a356a4a256f0456dc708 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:46:07 +0000 Subject: [PATCH 092/105] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 216f7a4..f3d7368 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.2-esm/index.mjs'; ``` #### array2iterator( src\[, mapFcn\[, thisArg]] ) @@ -193,7 +193,7 @@ var count = ctx.count; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; import inmap from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-inmap@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.2-esm/index.mjs'; function scale( v, i ) { return v * (i+1); From d5440bf2c5827eb6e3a8eb5ac17fb7b7cbb38761 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:46:08 +0000 Subject: [PATCH 093/105] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f3d7368..3410657 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@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/array-to-iterator/tags). For example, + ```javascript import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.2-esm/index.mjs'; ``` @@ -193,7 +198,7 @@ var count = ctx.count; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; import inmap from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-inmap@esm/index.mjs'; import randu from 'https://cdn.jsdelivr.net/gh/stdlib-js/random-base-randu@esm/index.mjs'; -import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@v0.2.2-esm/index.mjs'; +import array2iterator from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-to-iterator@esm/index.mjs'; function scale( v, i ) { return v * (i+1); From f6c430081307b93e995a9b9afd66704236629ff9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 08:18:29 +0000 Subject: [PATCH 094/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index 0758eee..ae0054a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.3.0", "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 315cc64f84c931963c042306c7184ab4d74347c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 13:10:51 +0000 Subject: [PATCH 095/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index af4c78b..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/assert-is-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 56be9ca..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7fcd30a166541e1b7bd9e211fc6250503991b71f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 13:11:09 +0000 Subject: [PATCH 096/105] 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 | 138 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4872 insertions(+), 4641 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 4248936..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T06:03:34.854Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..af4c78b --- /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/assert-is-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index ae0054a..e14cd15 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..56be9ca --- /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.js b/test/test.js deleted file mode 100644 index 65a4c72..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 8c16dbac12c1aab376c207b314379797c80c99c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:40:17 +0000 Subject: [PATCH 097/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index aed853b..dbea9cd 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.3.0", "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From ce63887252ad6797fb4e98046d9ac989abf7c8b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 13:12:01 +0000 Subject: [PATCH 098/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index af4c78b..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/assert-is-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 56be9ca..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 04be2d1ee2684095d52ad5cd2264a13b846e74cd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 13:12:16 +0000 Subject: [PATCH 099/105] 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 | 201 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 43 files changed, 4872 insertions(+), 4704 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 0955036..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:31:21.169Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index cead657..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value - - index: iterated value index - - src: source array-like object - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..af4c78b --- /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/assert-is-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index dbea9cd..e14cd15 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..56be9ca --- /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.js b/test/test.js deleted file mode 100644 index 65a4c72..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 9bf820f9f86001ffe33fefe4b2009f67e9c45bcd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 21:24:26 +0000 Subject: [PATCH 100/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index aed853b..dbea9cd 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.3.0", "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 379ebcac840d787760a834fa9e0e730f121eb11d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 21:25:30 +0000 Subject: [PATCH 101/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index af4c78b..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/assert-is-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 56be9ca..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5b85d960278a218afc711dd2cef05c06a4558bfa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 21 Sep 2024 21:25:43 +0000 Subject: [PATCH 102/105] 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 | 235 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4872 insertions(+), 4737 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a84a4d0..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value. - - index: iterated value index. - - src: source array-like object. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index 703a5c5..a24cec2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..af4c78b --- /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/assert-is-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index dbea9cd..e14cd15 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..56be9ca --- /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.js b/test/test.js deleted file mode 100644 index 65a4c72..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); From 8b33db889dac36c3c53d33cb924c1301063e79e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 18:02:55 +0000 Subject: [PATCH 103/105] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2df0ea0..7d0d775 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ var iteratorSymbol = require( '@stdlib/symbol-iterator' ); var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); var getter = require( '@stdlib/array-base-getter' ); var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -66,12 +66,12 @@ function array2iterator( src ) { var dt; var i; if ( !isCollection( src ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) ); + throw new TypeError( format( '01Z2O', src ) ); } if ( arguments.length > 1 ) { fcn = arguments[ 1 ]; if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + throw new TypeError( format( '01Z2H', fcn ) ); } thisArg = arguments[ 2 ]; } diff --git a/package.json b/package.json index aed853b..dbea9cd 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/array-dtype": "^0.3.0", "@stdlib/assert-is-collection": "^0.2.2", "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/symbol-iterator": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 3a83bca0666fb049e2862438a9b0cd98576eeaa0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 18:05:29 +0000 Subject: [PATCH 104/105] Remove files --- index.d.ts | 100 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4947 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 a24cec2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; -import { ArrayLike } from '@stdlib/types/array'; - -// Define a union type representing both iterable and non-iterable iterators: -type Iterator = Iter | IterableIterator; - -/** -* Map function invoked for each iterated value. -* -* @returns iterator value -*/ -type Nullary = () => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @returns iterator value -*/ -type Unary = ( value: any ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @returns iterator value -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type Ternary = ( value: any, index: number, src: ArrayLike ) => any; - -/** -* Map function invoked for each iterated value. -* -* @param value - iterated value -* @param index - iterated value index -* @param src - source array-like object -* @returns iterator value -*/ -type MapFunction = Nullary | Unary | Binary | Ternary; - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param src - input value -* @param mapFc - function to invoke for each iterated value -* @param thisArg - execution context -* @returns iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -declare function array2iterator( src: ArrayLike, mapFcn?: MapFunction, thisArg?: any ): Iterator; - - -// EXPORTS // - -export = array2iterator; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index af4c78b..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/assert-is-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f859a5a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 56be9ca..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From acc201f206b9e2c218fecdf964e4140e717e44c4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 18:05:46 +0000 Subject: [PATCH 105/105] 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 | 236 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/test.ts | 66 - examples/index.js | 44 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 50 - lib/main.js | 177 - package.json | 72 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 616 --- 42 files changed, 4872 insertions(+), 4738 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.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 (96%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 6f336a3..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/array/to-iterator) 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 c61f1ec..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/array/to-iterator) 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 0d355a6..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: '12 0 * * 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' - # 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 + + ```
@@ -267,7 +258,7 @@ while ( true ) { ## 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]. @@ -330,19 +321,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-to-iterator/main/LICENSE -[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator +[@stdlib/array/to-sparse-iterator]: https://github.com/stdlib-js/array-to-sparse-iterator/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator +[@stdlib/array/from-iterator]: https://github.com/stdlib-js/array-from-iterator/tree/esm -[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator +[@stdlib/array/to-circular-iterator]: https://github.com/stdlib-js/array-to-circular-iterator/tree/esm -[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right +[@stdlib/array/to-iterator-right]: https://github.com/stdlib-js/array-to-iterator-right/tree/esm -[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator +[@stdlib/array/to-strided-iterator]: https://github.com/stdlib-js/array-to-strided-iterator/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.js b/benchmark/benchmark.js deleted file mode 100644 index e05f4ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isnan = require( '@stdlib/math-base-assert-is-nan' ); -var isIteratorLike = require( '@stdlib/assert-is-iterator-like' ); -var pkg = require( './../package.json' ).name; -var array2iterator = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var values; - var iter; - var i; - - values = [ 1, 2, 3, 4 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - values[ 0 ] = i; - iter = array2iterator( values ); - if ( typeof iter !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isIteratorLike( iter ) ) { - b.fail( 'should return an iterator protocol-compliant object' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - } - b.toc(); - if ( z !== void 0 ) { - b.fail( 'should be undefined' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::iteration,map', function benchmark( b ) { - var values; - var iter; - var z; - var i; - - values = []; - values.length = b.iterations; - - iter = array2iterator( values, transform ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - z = iter.next().value; - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( z ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - - function transform( v, i ) { - return i; - } -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index e3943d3..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/array/to-iterator" -%% click B href "https://github.com/stdlib-js/array-to-iterator/tree/main" -%% click C href "https://github.com/stdlib-js/array-to-iterator/tree/production" -%% click D href "https://github.com/stdlib-js/array-to-iterator/tree/esm" -%% click E href "https://github.com/stdlib-js/array-to-iterator/tree/deno" -%% click F href "https://github.com/stdlib-js/array-to-iterator/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-iterator -[production-url]: https://github.com/stdlib-js/array-to-iterator/tree/production -[deno-url]: https://github.com/stdlib-js/array-to-iterator/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-to-iterator/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-to-iterator/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-to-iterator/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-to-iterator/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-to-iterator/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 b48072c..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array2iterator from '../docs/types/index'; -export = array2iterator; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index d67d3dd..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var x=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var d=x(function(T,g){ -var i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/assert-is-function/dist'),b=require('@stdlib/assert-is-collection/dist'),w=require('@stdlib/array-base-assert-is-accessor-array/dist'),f=require('@stdlib/symbol-iterator/dist'),A=require('@stdlib/array-base-accessor-getter/dist'),F=require('@stdlib/array-base-getter/dist'),E=require('@stdlib/array-dtype/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function v(e){var r,a,o,n,u,l,t;if(!b(e))throw new TypeError(s('01Z2O',e));if(arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s('01Z2H',n));r=arguments[2]}return t=-1,a={},n?i(a,"next",m):i(a,"next",q),i(a,"return",c),f&&i(a,f,y),l=E(e),w(e)?u=A(l):u=F(l),a;function m(){return t+=1,o||t>=e.length?{done:!0}:{value:n.call(r,u(e,t),t,e),done:!1}}function q(){return t+=1,o||t>=e.length?{done:!0}:{value:u(e,t),done:!1}}function c(h){return o=!0,arguments.length?{value:h,done:!0}:{done:!0}}function y(){return n?v(e,n,r):v(e)}}g.exports=v -});var G=d();module.exports=G; -/** @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 474f261..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' );\nvar iteratorSymbol = require( '@stdlib/symbol-iterator' );\nvar accessorGetter = require( '@stdlib/array-base-accessor-getter' );\nvar getter = require( '@stdlib/array-base-getter' );\nvar dtype = require( '@stdlib/array-dtype' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = array2iterator;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Create an iterator from an array-like object.\n*\n* @module @stdlib/array-to-iterator\n*\n* @example\n* var array2iterator = require( '@stdlib/array-to-iterator' );\n*\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAkB,QAAS,6CAA8C,EACzEC,EAAiB,QAAS,yBAA0B,EACpDC,EAAiB,QAAS,oCAAqC,EAC/DC,EAAS,QAAS,2BAA4B,EAC9CC,EAAQ,QAAS,qBAAsB,EACvCC,EAAS,QAAS,uBAAwB,EA6B9C,SAASC,EAAgBC,EAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,GAAK,CAACf,EAAcQ,CAAI,EACvB,MAAM,IAAI,UAAWF,EAAQ,8EAA+EE,CAAI,CAAE,EAEnH,GAAK,UAAU,OAAS,EAAI,CAE3B,GADAI,EAAM,UAAW,CAAE,EACd,CAACb,EAAYa,CAAI,EACrB,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAI,CAAE,EAE1GH,EAAU,UAAW,CAAE,CACxB,CACA,OAAAM,EAAI,GAGJL,EAAO,CAAC,EACHE,EACJd,EAAaY,EAAM,OAAQM,CAAM,EAEjClB,EAAaY,EAAM,OAAQO,CAAM,EAElCnB,EAAaY,EAAM,SAAUQ,CAAI,EAG5BhB,GACJJ,EAAaY,EAAMR,EAAgBiB,CAAQ,EAG5CL,EAAKT,EAAOG,CAAI,EACXP,EAAiBO,CAAI,EACzBK,EAAMV,EAAgBW,CAAG,EAEzBD,EAAMT,EAAQU,CAAG,EAEXJ,EAQP,SAASM,GAAQ,CAEhB,OADAD,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASI,EAAI,KAAMH,EAASI,EAAKL,EAAKO,CAAE,EAAGA,EAAGP,CAAI,EAClD,KAAQ,EACT,CACD,CAQA,SAASS,GAAQ,CAEhB,OADAF,GAAK,EACAJ,GAAOI,GAAKP,EAAI,OACb,CACN,KAAQ,EACT,EAEM,CACN,MAASK,EAAKL,EAAKO,CAAE,EACrB,KAAQ,EACT,CACD,CASA,SAASG,EAAKE,EAAQ,CAErB,OADAT,EAAM,GACD,UAAU,OACP,CACN,MAASS,EACT,KAAQ,EACT,EAEM,CACN,KAAQ,EACT,CACD,CAQA,SAASD,GAAU,CAClB,OAAKP,EACGL,EAAgBC,EAAKI,EAAKH,CAAQ,EAEnCF,EAAgBC,CAAI,CAC5B,CACD,CAKAX,EAAO,QAAUU,ICpIjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "setReadOnly", "isFunction", "isCollection", "isAccessorArray", "iteratorSymbol", "accessorGetter", "getter", "dtype", "format", "array2iterator", "src", "thisArg", "iter", "FLG", "fcn", "get", "dt", "i", "next1", "next2", "end", "factory", "value", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a84a4d0..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( src[, mapFcn[, thisArg]] ) - Returns an iterator which iterates over the elements of an array-like - object. - - When invoked, an input function is provided three arguments: - - - value: iterated value. - - index: iterated value index. - - src: source array-like object. - - If an environment supports Symbol.iterator, the returned iterator is - iterable. - - If an environment supports Symbol.iterator, the function explicitly does not - invoke an array's `@@iterator` method, regardless of whether this method is - defined. To convert an array to an implementation defined iterator, invoke - this method directly. - - Parameters - ---------- - src: ArrayLikeObject - Array-like object from which to create the iterator. - - mapFcn: Function (optional) - Function to invoke for each iterated value. - - thisArg: any (optional) - Execution context. - - Returns - ------- - iterator: Object - Iterator. - - iterator.next(): Function - Returns an iterator protocol-compliant object containing the next - iterated value (if one exists) and a boolean flag indicating whether the - iterator is finished. - - iterator.return( [value] ): Function - Finishes an iterator and returns a provided value. - - Examples - -------- - > var it = {{alias}}( [ 1, 2, 3, 4 ] ); - > var v = it.next().value - 1 - > v = it.next().value - 2 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 561feb7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 array2iterator = require( './index' ); - -/** -* Multiplies a value by 10. -* -* @param v - iterated value -* @returns new value -*/ -function times10( v: number ): number { - return v * 10.0; -} - - -// TESTS // - -// The function returns an iterator... -{ - array2iterator( [ 1, 2, 3, 4 ] ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10 ); // $ExpectType Iterator - array2iterator( [ 1, 2, 3, 4 ], times10, {} ); // $ExpectType Iterator -} - -// The compiler throws an error if the function is provided a first argument which is not array-like... -{ - array2iterator( 123 ); // $ExpectError - array2iterator( true ); // $ExpectError - array2iterator( false ); // $ExpectError - array2iterator( {} ); // $ExpectError - array2iterator( null ); // $ExpectError - array2iterator( undefined ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a map function... -{ - array2iterator( [ 1, 2, 3, 4 ], 'abc' ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], 123 ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], [] ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], {} ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], true ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], false ); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], null ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - array2iterator(); // $ExpectError - array2iterator( [ 1, 2, 3, 4 ], times10, {}, 123 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index d17e3c1..0000000 --- a/examples/index.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 Float64Array = require( '@stdlib/array-float64' ); -var inmap = require( '@stdlib/utils-inmap' ); -var randu = require( '@stdlib/random-base-randu' ); -var array2iterator = require( './../lib' ); - -function scale( v, i ) { - return v * (i+1); -} - -// Create an array filled with random numbers: -var arr = inmap( new Float64Array( 100 ), randu ); - -// Create an iterator from the array which scales iterated values: -var it = array2iterator( arr, scale ); - -// Perform manual iteration... -var v; -while ( true ) { - v = it.next(); - if ( v.done ) { - break; - } - console.log( v.value ); -} diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 96% rename from docs/types/index.d.ts rename to index.d.ts index d5e6f59..17fd7a6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..af4c78b --- /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/assert-is-collection@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-accessor-array@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/symbol-iterator@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessor-getter@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-getter@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.3.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function l(a){var j,f,p,h,c,u,v;if(!r(a))throw new TypeError(m("01Z2O",a));if(arguments.length>1){if(!t(h=arguments[1]))throw new TypeError(m("01Z2H",h));j=arguments[2]}return v=-1,e(f={},"next",h?function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:h.call(j,c(a,v),v,a),done:!1}}:function(){if(v+=1,p||v>=a.length)return{done:!0};return{value:c(a,v),done:!1}}),e(f,"return",(function(e){if(p=!0,arguments.length)return{value:e,done:!0};return{done:!0}})),n&&e(f,n,(function(){if(h)return l(a,h,j);return l(a)})),u=d(a),c=s(a)?i(u):o(u),f}export{l as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f859a5a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.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 setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport isFunction from '@stdlib/assert-is-function';\nimport isCollection from '@stdlib/assert-is-collection';\nimport isAccessorArray from '@stdlib/array-base-assert-is-accessor-array';\nimport iteratorSymbol from '@stdlib/symbol-iterator';\nimport accessorGetter from '@stdlib/array-base-accessor-getter';\nimport getter from '@stdlib/array-base-getter';\nimport dtype from '@stdlib/array-dtype';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Returns an iterator which iterates over each element in an array-like object.\n*\n* @param {Collection} src - input value\n* @param {Function} [mapFcn] - function to invoke for each iterated value\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be an array-like object\n* @throws {TypeError} second argument must be a function\n* @returns {Iterator} iterator\n*\n* @example\n* var iter = array2iterator( [ 1, 2, 3, 4 ] );\n*\n* var v = iter.next().value;\n* // returns 1\n*\n* v = iter.next().value;\n* // returns 2\n*\n* v = iter.next().value;\n* // returns 3\n*\n* // ...\n*/\nfunction array2iterator( src ) {\n\tvar thisArg;\n\tvar iter;\n\tvar FLG;\n\tvar fcn;\n\tvar get;\n\tvar dt;\n\tvar i;\n\tif ( !isCollection( src ) ) {\n\t\tthrow new TypeError( format( '01Z2O', src ) );\n\t}\n\tif ( arguments.length > 1 ) {\n\t\tfcn = arguments[ 1 ];\n\t\tif ( !isFunction( fcn ) ) {\n\t\t\tthrow new TypeError( format( '01Z2H', fcn ) );\n\t\t}\n\t\tthisArg = arguments[ 2 ];\n\t}\n\ti = -1;\n\n\t// Create an iterator protocol-compliant object:\n\titer = {};\n\tif ( fcn ) {\n\t\tsetReadOnly( iter, 'next', next1 );\n\t} else {\n\t\tsetReadOnly( iter, 'next', next2 );\n\t}\n\tsetReadOnly( iter, 'return', end );\n\n\t// If an environment supports `Symbol.iterator`, make the iterator iterable:\n\tif ( iteratorSymbol ) {\n\t\tsetReadOnly( iter, iteratorSymbol, factory );\n\t}\n\t// Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc):\n\tdt = dtype( src );\n\tif ( isAccessorArray( src ) ) {\n\t\tget = accessorGetter( dt );\n\t} else {\n\t\tget = getter( dt );\n\t}\n\treturn iter;\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next1() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': fcn.call( thisArg, get( src, i ), i, src ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Returns an iterator protocol-compliant object containing the next iterated value.\n\t*\n\t* @private\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction next2() {\n\t\ti += 1;\n\t\tif ( FLG || i >= src.length ) {\n\t\t\treturn {\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'value': get( src, i ),\n\t\t\t'done': false\n\t\t};\n\t}\n\n\t/**\n\t* Finishes an iterator.\n\t*\n\t* @private\n\t* @param {*} [value] - value to return\n\t* @returns {Object} iterator protocol-compliant object\n\t*/\n\tfunction end( value ) {\n\t\tFLG = true;\n\t\tif ( arguments.length ) {\n\t\t\treturn {\n\t\t\t\t'value': value,\n\t\t\t\t'done': true\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\t'done': true\n\t\t};\n\t}\n\n\t/**\n\t* Returns a new iterator.\n\t*\n\t* @private\n\t* @returns {Iterator} iterator\n\t*/\n\tfunction factory() {\n\t\tif ( fcn ) {\n\t\t\treturn array2iterator( src, fcn, thisArg );\n\t\t}\n\t\treturn array2iterator( src );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default array2iterator;\n"],"names":["array2iterator","src","thisArg","iter","FLG","fcn","get","dt","i","isCollection","TypeError","format","arguments","length","isFunction","setReadOnly","done","value","call","iteratorSymbol","dtype","isAccessorArray","accessorGetter","getter"],"mappings":";;o3BA2DA,SAASA,EAAgBC,GACxB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,IAAMC,EAAcR,GACnB,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,GAAKW,UAAUC,OAAS,EAAI,CAE3B,IAAMC,EADNT,EAAMO,UAAW,IAEhB,MAAM,IAAIF,UAAWC,EAAQ,QAASN,IAEvCH,EAAUU,UAAW,EACrB,CAuBD,OAtBAJ,GAAK,EAKJO,EAFDZ,EAAO,CAAA,EAEa,OADfE,EA0BL,WAEC,GADAG,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASZ,EAAIa,KAAMhB,EAASI,EAAKL,EAAKO,GAAKA,EAAGP,GAC9Ce,MAAQ,EAET,EAQD,WAEC,GADAR,GAAK,EACAJ,GAAOI,GAAKP,EAAIY,OACpB,MAAO,CACNG,MAAQ,GAGV,MAAO,CACNC,MAASX,EAAKL,EAAKO,GACnBQ,MAAQ,EAET,GAnDDD,EAAaZ,EAAM,UA4DnB,SAAcc,GAEb,GADAb,GAAM,EACDQ,UAAUC,OACd,MAAO,CACNI,MAASA,EACTD,MAAQ,GAGV,MAAO,CACNA,MAAQ,EAET,IApEIG,GACJJ,EAAaZ,EAAMgB,GA2EpB,WACC,GAAKd,EACJ,OAAOL,EAAgBC,EAAKI,EAAKH,GAElC,OAAOF,EAAgBC,EACvB,IA7EDM,EAAKa,EAAOnB,GAEXK,EADIe,EAAiBpB,GACfqB,EAAgBf,GAEhBgB,EAAQhB,GAERJ,CAwER"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 541e78d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Create an iterator from an array-like object. -* -* @module @stdlib/array-to-iterator -* -* @example -* var array2iterator = require( '@stdlib/array-to-iterator' ); -* -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7d0d775..0000000 --- a/lib/main.js +++ /dev/null @@ -1,177 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isAccessorArray = require( '@stdlib/array-base-assert-is-accessor-array' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var accessorGetter = require( '@stdlib/array-base-accessor-getter' ); -var getter = require( '@stdlib/array-base-getter' ); -var dtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns an iterator which iterates over each element in an array-like object. -* -* @param {Collection} src - input value -* @param {Function} [mapFcn] - function to invoke for each iterated value -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an array-like object -* @throws {TypeError} second argument must be a function -* @returns {Iterator} iterator -* -* @example -* var iter = array2iterator( [ 1, 2, 3, 4 ] ); -* -* var v = iter.next().value; -* // returns 1 -* -* v = iter.next().value; -* // returns 2 -* -* v = iter.next().value; -* // returns 3 -* -* // ... -*/ -function array2iterator( src ) { - var thisArg; - var iter; - var FLG; - var fcn; - var get; - var dt; - var i; - if ( !isCollection( src ) ) { - throw new TypeError( format( '01Z2O', src ) ); - } - if ( arguments.length > 1 ) { - fcn = arguments[ 1 ]; - if ( !isFunction( fcn ) ) { - throw new TypeError( format( '01Z2H', fcn ) ); - } - thisArg = arguments[ 2 ]; - } - i = -1; - - // Create an iterator protocol-compliant object: - iter = {}; - if ( fcn ) { - setReadOnly( iter, 'next', next1 ); - } else { - setReadOnly( iter, 'next', next2 ); - } - setReadOnly( iter, 'return', end ); - - // If an environment supports `Symbol.iterator`, make the iterator iterable: - if ( iteratorSymbol ) { - setReadOnly( iter, iteratorSymbol, factory ); - } - // Resolve an accessor for retrieving array elements (e.g., to accommodate `Complex64Array`, etc): - dt = dtype( src ); - if ( isAccessorArray( src ) ) { - get = accessorGetter( dt ); - } else { - get = getter( dt ); - } - return iter; - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next1() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': fcn.call( thisArg, get( src, i ), i, src ), - 'done': false - }; - } - - /** - * Returns an iterator protocol-compliant object containing the next iterated value. - * - * @private - * @returns {Object} iterator protocol-compliant object - */ - function next2() { - i += 1; - if ( FLG || i >= src.length ) { - return { - 'done': true - }; - } - return { - 'value': get( src, i ), - 'done': false - }; - } - - /** - * Finishes an iterator. - * - * @private - * @param {*} [value] - value to return - * @returns {Object} iterator protocol-compliant object - */ - function end( value ) { - FLG = true; - if ( arguments.length ) { - return { - 'value': value, - 'done': true - }; - } - return { - 'done': true - }; - } - - /** - * Returns a new iterator. - * - * @private - * @returns {Iterator} iterator - */ - function factory() { - if ( fcn ) { - return array2iterator( src, fcn, thisArg ); - } - return array2iterator( src ); - } -} - - -// EXPORTS // - -module.exports = array2iterator; diff --git a/package.json b/package.json index dbea9cd..e14cd15 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an iterator from an array-like object.", "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,51 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessor-getter": "^0.2.2", - "@stdlib/array-base-assert-is-accessor-array": "^0.2.2", - "@stdlib/array-base-getter": "^0.2.2", - "@stdlib/array-dtype": "^0.3.0", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/symbol-iterator": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-iterator-like": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/random-base-randu": "^0.2.1", - "@stdlib/utils-inmap": "^0.2.2", - "@stdlib/utils-noop": "^0.2.2", - "proxyquire": "^2.0.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.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..56be9ca --- /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.js b/test/test.js deleted file mode 100644 index 65a4c72..0000000 --- a/test/test.js +++ /dev/null @@ -1,616 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var iteratorSymbol = require( '@stdlib/symbol-iterator' ); -var noop = require( '@stdlib/utils-noop' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var array2iterator = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof array2iterator, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an array-like object (callback)', function test( t ) { - var values; - var i; - - 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 an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - array2iterator( [ 1, 2, 3, 4 ], value ); - }; - } -}); - -tape( 'the function returns an iterator protocol-compliant object', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - expected = [ - { - 'value': 1, - 'done': false - }, - { - 'value': 2, - 'done': false - }, - { - 'value': 3, - 'done': false - }, - { - 'value': 4, - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.deepEqual( actual, expected, 'returns expected values' ); - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 1.0, 2.0 ), - 'done': false - }, - { - 'value': new Complex64( 3.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 5.0, 6.0 ), - 'done': false - }, - { - 'value': new Complex64( 7.0, 8.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = [ 1, 2, 3, 4 ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (array-like)', function test( t ) { - var expected; - var values; - var it; - var r; - var i; - - values = { - 'length': 4, - '0': 1, - '1': 2, - '2': 3, - '3': 4 - }; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - expected = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - t.equal( r.value, expected[ i ], 'returns expected value' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - t.equal( expected.length, values.length, 'has expected length' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - v *= i + 1; - expected.push( v ); - return v; - } -}); - -tape( 'the function returns an iterator protocol-compliant object which supports invoking a provided function for each iterated value (accessors)', function test( t ) { - var expected; - var actual; - var values; - var it; - var v1; - var v2; - var r; - var i; - - values = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - expected = [ - { - 'value': new Complex64( 2.0, 4.0 ), - 'done': false - }, - { - 'value': new Complex64( 6.0, 8.0 ), - 'done': false - }, - { - 'value': new Complex64( 10.0, 12.0 ), - 'done': false - }, - { - 'value': new Complex64( 14.0, 16.0 ), - 'done': false - }, - { - 'done': true - } - ]; - - it = array2iterator( values, scale ); - t.equal( it.next.length, 0, 'has zero arity' ); - - actual = []; - for ( i = 0; i < values.length; i++ ) { - r = it.next(); - actual.push( r ); - t.equal( typeof r.value, 'object', 'returns an object' ); - t.equal( typeof r.done, 'boolean', 'returns a boolean' ); - } - actual.push( it.next() ); - - t.equal( actual.length, expected.length, 'returns expected value' ); - for ( i = 0; i < expected.length; i++ ) { - v1 = actual[ i ]; - v2 = expected[ i ]; - if ( i < expected.length-1 ) { - t.equal( realf( v1.value ), realf( v2.value ), 'returns expected value' ); - t.equal( imagf( v1.value ), imagf( v2.value ), 'returns expected value' ); - } - t.equal( v1.done, v2.done, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return new Complex64( realf( v )*2.0, imagf( v )*2.0 ); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (no argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ] ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned iterator has a `return` method for closing an iterator (argument; callback)', function test( t ) { - var it; - var r; - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.next(); - t.equal( typeof r.value, 'number', 'returns a number' ); - t.equal( r.done, false, 'returns expected value' ); - - r = it.return( 'finished' ); - t.equal( r.value, 'finished', 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - r = it.next(); - t.equal( r.value, void 0, 'returns expected value' ); - t.equal( r.done, true, 'returns expected value' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable (callback)', function test( t ) { - var array2iterator; - var values; - var it1; - var it2; - var i; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': '__ITERATOR_SYMBOL__' - }); - - values = [ 1, 2, 3, 4 ]; - - it1 = array2iterator( values, scale ); - t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); - t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); - - it2 = it1[ '__ITERATOR_SYMBOL__' ](); - t.equal( typeof it2, 'object', 'returns an object' ); - t.equal( typeof it2.next, 'function', 'has method' ); - t.equal( typeof it2.return, 'function', 'has method' ); - - for ( i = 0; i < values.length; i++ ) { - t.equal( it2.next().value, it1.next().value, 'returns expected value' ); - } - t.end(); - - function scale( v ) { - return v * 10.0; - } -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ] ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); -}); - -tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable" (callback)', function test( t ) { - var array2iterator; - var it; - - array2iterator = proxyquire( './../lib/main.js', { - '@stdlib/symbol-iterator': false - }); - - it = array2iterator( [ 1, 2, 3, 4 ], scale ); - t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); - - t.end(); - - function scale( v, i ) { - return v * (i+1); - } -});