From 5ae442b49ed4beb2781a1a3d525b42bc79811033 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 09:37:34 +0000 Subject: [PATCH 001/120] Auto-generated commit 6d841f7b695461d8fcc8dc50ba3c87ff1d3fe8af --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 303 ++++++ index.d.ts | 54 + index.mjs | 4 + index.mjs.map | 1 + package.json | 32 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3593 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..50e32ff --- /dev/null +++ b/README.md @@ -0,0 +1,303 @@ + + +# Array Shape + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Determine (nested) array dimensions. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import arrayShape from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs'; +``` + +#### arrayShape( arr ) + +Returns array dimensions. + +```javascript +var arr = [ + [ 1, 2, 3 ], + [ 4, 5, 6 ], + [ 7, 8, 9 ] +]; + +var shape = arrayShape( arr ); +// returns [ 3, 3 ] +``` + +The function **ignores** inconsistent dimensions. + +```javascript +var arr = [ + [ 1, 2, 3 ], + [ 4, 5, 6 ], + [ 7, 8 ] +]; + +var shape = arrayShape( arr ); +// returns [ 3 ] +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## 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..b6771e7 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,54 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 { ArrayLike } from '@stdlib/types/array'; + +/** +* Determines (nested) array dimensions. +* +* @param arr - array +* @returns array shape +* +* @example +* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; +* +* var shape = arrayShape( arr ); +* // returns [ 3, 3 ] +* +* @example +* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; +* +* var shape = arrayShape( arr ); +* // returns [ 3 ] +* +* @example +* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; +* +* var shape = arrayShape( arr ); +* // returns [ 3 ] +*/ +declare function arrayShape( arr: ArrayLike ): Array; + + +// EXPORTS // + +export = arrayShape; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..71a4c12 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var e=r,n=t;function i(r,t){var n=t[0];return e(n)&&(r.push(n.length),i(r,n)),r}function s(r,t,n,i,a){var l,o,u;for(l=t[n],u=0;u1&&(t.length=s(a,t,1,r,a>2)),t};export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..94a3411 --- /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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],"names":["isArrayLikeObject","require$$0","format","require$$1","recurse","shape","arr","v","push","length","check","ndims","d","flg","len","i","lib","TypeError"],"mappings":";;gLAsBA,IAAIA,EAAoBC,EACpBC,EAASC,EAab,SAASC,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKN,EAAmBO,KACvBF,EAAMG,KAAMD,EAAEE,QACdL,EAASC,EAAOE,IAEVF,EAcR,SAASK,EAAOC,EAAON,EAAOO,EAAGN,EAAKO,GACrC,IAAIC,EACAP,EACAQ,EAMJ,IAHAD,EAAMT,EAAOO,GAGPG,EAAI,EAAGA,EAAIT,EAAIG,OAAQM,IAAM,CAIlC,GAHAR,EAAID,EAAKS,IAGHf,EAAmBO,IAAOA,EAAEE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJN,EAAIG,EAAOC,EAAON,EAAOO,EAAE,EAAGL,EAAGK,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOJ,EAIV,OAAOI,EAwDR,ICjFAK,EDwDA,SAAqBV,GACpB,IAAID,EACAM,EAEJ,IAAMX,EAAmBM,GACxB,MAAM,IAAIW,UAAWf,EAAQ,oEAAqEI,IAcnG,OARAF,EAHAC,EAAQ,CAAEC,EAAIG,QAGEH,IAChBK,EAAQN,EAAMI,QAGD,IAEZJ,EAAMI,OAASC,EAAOC,EAAON,EAAO,EAAGC,EAAKK,EAAQ,IAE9CN"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..0b718c8 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "@stdlib/array-shape", + "version": "0.0.0", + "description": "Determine (nested) array dimensions.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/array-shape.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdtypes", + "utils", + "util", + "utilities", + "utility", + "array", + "dims", + "dimensions", + "shape" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cebec1c --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From a8d9f76e7c3450d513b2c9a7769a774bfb2f3ddd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:30:58 +0000 Subject: [PATCH 002/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 555bec0..c12f138 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From ccf8777ac96a447e092af38bf4cc9ee4c582b992 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:41:51 +0000 Subject: [PATCH 003/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 71a4c12..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var e=r,n=t;function i(r,t){var n=t[0];return e(n)&&(r.push(n.length),i(r,n)),r}function s(r,t,n,i,a){var l,o,u;for(l=t[n],u=0;u1&&(t.length=s(a,t,1,r,a>2)),t};export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 94a3411..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],"names":["isArrayLikeObject","require$$0","format","require$$1","recurse","shape","arr","v","push","length","check","ndims","d","flg","len","i","lib","TypeError"],"mappings":";;gLAsBA,IAAIA,EAAoBC,EACpBC,EAASC,EAab,SAASC,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKN,EAAmBO,KACvBF,EAAMG,KAAMD,EAAEE,QACdL,EAASC,EAAOE,IAEVF,EAcR,SAASK,EAAOC,EAAON,EAAOO,EAAGN,EAAKO,GACrC,IAAIC,EACAP,EACAQ,EAMJ,IAHAD,EAAMT,EAAOO,GAGPG,EAAI,EAAGA,EAAIT,EAAIG,OAAQM,IAAM,CAIlC,GAHAR,EAAID,EAAKS,IAGHf,EAAmBO,IAAOA,EAAEE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJN,EAAIG,EAAOC,EAAON,EAAOO,EAAE,EAAGL,EAAGK,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOJ,EAIV,OAAOI,EAwDR,ICjFAK,EDwDA,SAAqBV,GACpB,IAAID,EACAM,EAEJ,IAAMX,EAAmBM,GACxB,MAAM,IAAIW,UAAWf,EAAQ,oEAAqEI,IAcnG,OARAF,EAHAC,EAAQ,CAAEC,EAAIG,QAGEH,IAChBK,EAAQN,EAAMI,QAGD,IAEZJ,EAAMI,OAASC,EAAOC,EAAON,EAAO,EAAGC,EAAKK,EAAQ,IAE9CN"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cebec1c..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 90fb726c1618cf619f8069d94552bc3c30d8ea4e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:42:26 +0000 Subject: [PATCH 004/120] 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 | 35 +- benchmark/benchmark.js | 220 -- branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 -- package.json | 55 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 378 --- 37 files changed, 2711 insertions(+), 3964 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 (93%) 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 aa037a8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:10:26.367Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3b6815a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..4e9aae0 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;yLAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index c12f138..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c8cafdf --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From f40de62553b2493b9dd3527c7a68b82c5005b72e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:42:55 +0000 Subject: [PATCH 005/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 555bec0..c12f138 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From acffe303d58cb001167b3a32857769b3e43e6b4c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:06:24 +0000 Subject: [PATCH 006/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3b6815a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 4e9aae0..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;yLAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c8cafdf..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 27d7f63281ff537511b8d421b0bd3c22469365a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:07:01 +0000 Subject: [PATCH 007/120] 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 | 35 +- benchmark/benchmark.js | 220 -- branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 -- package.json | 55 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 378 --- 36 files changed, 2711 insertions(+), 3929 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 (93%) 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 dd48555..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/shape) 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 5800fd4..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/shape) 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3b6815a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..4e9aae0 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;yLAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index c12f138..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..62e850c --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From dfb570c50c9f7c3bca5cad47b1bf0333eccfa46b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:53:44 +0000 Subject: [PATCH 008/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 555bec0..c12f138 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From da5d87f975d38e16c25b8b9d80c7453352f7359b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:18:53 +0000 Subject: [PATCH 009/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3b6815a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 4e9aae0..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;yLAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 62e850c..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 34cfec2ec6faa1cd4cadc47970802db4f42e7d09 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:19:35 +0000 Subject: [PATCH 010/120] 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 | 35 +- benchmark/benchmark.js | 220 -- branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 -- package.json | 55 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 378 --- 37 files changed, 2711 insertions(+), 4003 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 (93%) 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 a86f92c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:13:35.306Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c415e0e --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5b14601 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index c12f138..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4460cda --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 40d321d39b15b3f11ac5ae20e793fca21bd6c41c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:40:44 +0000 Subject: [PATCH 011/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 555bec0..c12f138 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 1e913ef0deaae69de2c0bf6dc6b2fc5646edc30a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 17:04:39 +0000 Subject: [PATCH 012/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c415e0e..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5b14601..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4460cda..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a10b9f633863689d1936fa512dcdcd7f808a0989 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 17:05:12 +0000 Subject: [PATCH 013/120] 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 | 35 +- benchmark/benchmark.js | 220 -- branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 -- package.json | 55 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 378 --- 37 files changed, 2711 insertions(+), 4019 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 (93%) 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 8493700..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:11:29.098Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c415e0e --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5b14601 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index c12f138..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2407a60 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From e38e0574f4370bdb79b40e4e5ddd0e3467a6d9d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 03:58:05 +0000 Subject: [PATCH 014/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 555bec0..c12f138 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 13109540169e29d0cd78cb1dd9f188b5024a39ba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 15:19:08 +0000 Subject: [PATCH 015/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c415e0e..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5b14601..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2407a60..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 36b326bf29e85c66cf6924f21c0bfb31c06dc55f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 15:19:50 +0000 Subject: [PATCH 016/120] 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 | 35 +- benchmark/benchmark.js | 220 -- branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 -- package.json | 55 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 378 --- 37 files changed, 2711 insertions(+), 4019 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 (93%) 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 8d2ee18..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:36:21.878Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c415e0e --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..5b14601 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index c12f138..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..01b8277 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From d7b763d29ddce6b1620cba6cd1f3c40054c38231 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:46:29 +0000 Subject: [PATCH 017/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 555bec0..c12f138 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 243d6b5cac4d758fe24bd148eb1a6c6dfdd18875 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:32:36 +0000 Subject: [PATCH 018/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2748 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c415e0e..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 5b14601..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,EAcR,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,EAIV,OAAOK,EA+BR,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 01b8277..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 35998169b9b7f38236a619e4b6eeecd6f1e003e5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:33:16 +0000 Subject: [PATCH 019/120] 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 | 35 +- benchmark/benchmark.js | 220 -- branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 4066 insertions(+), 4019 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 (93%) 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 67cae7a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:24:35.720Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c415e0e --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..527def1 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index c12f138..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e235071 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 9d11acbd097bf67d4c89797d20d61f7268ec1c15 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:11:06 +0000 Subject: [PATCH 020/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 555bec0..c12f138 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From edff6c2c9c2003c0f953e3a18f52dbe3e6cdcd2f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 13:30:34 +0000 Subject: [PATCH 021/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4103 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c415e0e..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 527def1..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e235071..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From aefcfbd36aa5794326ca12f1b518342d5e7b4da3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 13:31:10 +0000 Subject: [PATCH 022/120] 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 | 35 +- benchmark/benchmark.js | 220 -- branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 4066 insertions(+), 4040 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 (93%) 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 dd35286..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:00:50.309Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c415e0e --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..527def1 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index c12f138..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ef702e2 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 33fe6c10c7a929fccc691450e12de5e19a52b0fd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:01:57 +0000 Subject: [PATCH 023/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index cb15639..0d40f95 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From fe643a64ea4f63eed21ce2e57b32ca434b12bc31 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 20:36:42 +0000 Subject: [PATCH 024/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4103 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c415e0e..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 527def1..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ef702e2..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f0dcba8f167b1e647232a30495b299c7cc49df01 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 20:37:39 +0000 Subject: [PATCH 025/120] 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 | 35 +- benchmark/benchmark.js | 220 -- branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 4066 insertions(+), 4045 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 (93%) 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 59bdbff..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T01:50:33.146Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c415e0e --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a0a1962 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 0d40f95..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7b375dd --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 444d916e911154b418eea9df521f2081502f7773 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 03:12:19 +0000 Subject: [PATCH 026/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 87d191a..4ea4994 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From f972e234049fa1c09f867b896ba7b298f8518b94 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 07:58:26 +0000 Subject: [PATCH 027/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4103 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c415e0e..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a0a1962..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7b375dd..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 5d9604f53a71b36d4d2dd82e9462e16809d41e0d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 07:59:12 +0000 Subject: [PATCH 028/120] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 35 +- benchmark/benchmark.js | 220 -- branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 4066 insertions(+), 4056 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 (93%) 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 254fc6e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T01:14:51.452Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4c28a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a0a1962 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 4ea4994..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8536b03 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 929a4669497db432c5e0c9a100983740bc69dbf4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:51:12 +0000 Subject: [PATCH 029/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 87d191a..4ea4994 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 55fea2ea362fdd7ab1b0caa27da3b22a855d46a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 15:04:41 +0000 Subject: [PATCH 030/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4103 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4c28a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a0a1962..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8536b03..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From cd753d21955269e7471fcc8d8508ea4ce251f497 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 15:05:20 +0000 Subject: [PATCH 031/120] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 --- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 6199 insertions(+), 4056 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 (93%) 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 d6c9390..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T01:38:47.458Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index b827c48..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/shape" -click B href "https://github.com/stdlib-js/array-shape/tree/main" -click C href "https://github.com/stdlib-js/array-shape/tree/production" -click D href "https://github.com/stdlib-js/array-shape/tree/esm" -click E href "https://github.com/stdlib-js/array-shape/tree/deno" -click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4c28a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a0a1962 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 4ea4994..5dcea9b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a387506 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From a1b88b8bfed49345f054b0d386a1868cae80e631 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 06:16:33 +0000 Subject: [PATCH 032/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 5e3a438..99d5c75 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 034e09315d23710334f39aca9e5e713394efc869 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 15:11:51 +0000 Subject: [PATCH 033/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4c28a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a0a1962..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a387506..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e084a47bc16f1a90b3655ba892dde00412622c60 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 15:12:32 +0000 Subject: [PATCH 034/120] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 236 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 6199 insertions(+), 4191 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 (93%) 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 317fbbc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T04:02:24.514Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4c28a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a0a1962 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 99d5c75..42734e5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "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..cdee986 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 4378783ddaa6119b2fb93d1731c3701690395f8c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 06:51:36 +0000 Subject: [PATCH 035/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 5e3a438..99d5c75 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From e3a1a5cc36d18431845dcb91b36e551d58f059dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 14:14:17 +0000 Subject: [PATCH 036/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4c28a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a0a1962..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cdee986..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d8b5efad4b2bf6d3b4951cdcb8fb724df889c224 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 14:15:02 +0000 Subject: [PATCH 037/120] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 6199 insertions(+), 4197 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 (93%) 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 8199f69..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T04:37:22.973Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4c28a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a0a1962 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 99d5c75..42734e5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "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..92902c5 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From c559d4e59f0621d0e49158b96609e83232b27d23 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 06:35:33 +0000 Subject: [PATCH 038/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 5e3a438..99d5c75 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 109001434d025b6244d5733b3feb62a0fb42a794 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 13:51:23 +0000 Subject: [PATCH 039/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4c28a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a0a1962..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 92902c5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 62afb799f38b2d253e7586e4f67dbd5253c9cd68 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 13:51:58 +0000 Subject: [PATCH 040/120] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 6199 insertions(+), 4197 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 (93%) 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 fc783fd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T04:22:46.105Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4c28a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a0a1962 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 99d5c75..42734e5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "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..d8054d0 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 6eb2d66c74493036cadd46b6db01e17fa921282f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 06:15:45 +0000 Subject: [PATCH 041/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 5e3a438..99d5c75 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From e9012fe260e9461fda11bf303491d750701c3382 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 14:01:31 +0000 Subject: [PATCH 042/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4c28a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a0a1962..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d8054d0..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f36a54b4257eb1471f83d6097475c058bc1a782c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 14:02:09 +0000 Subject: [PATCH 043/120] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 6199 insertions(+), 4197 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 (93%) 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 f223ff9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T04:01:46.669Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4c28a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a0a1962 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 99d5c75..42734e5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "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..029ef98 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From d26831a02fa132153304ef885744476ee61fe679 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 06:17:08 +0000 Subject: [PATCH 044/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 5e3a438..99d5c75 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 169b31622f1a7defa4e04164b1c0c0c9a3ea207a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 14:14:39 +0000 Subject: [PATCH 045/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4c28a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a0a1962..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 029ef98..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1e3b6903523dfa27e1b1c27253a39af28852613d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 14:15:28 +0000 Subject: [PATCH 046/120] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 6199 insertions(+), 4197 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 (93%) 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 917a06d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T04:02:14.683Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4c28a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a0a1962 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 99d5c75..42734e5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "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..d0af8fe --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From a5c46b6220351bdf7460baa503057793d2e51066 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 06:49:08 +0000 Subject: [PATCH 047/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..bb7737e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '00i36', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 5e3a438..99d5c75 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 30a02a1192ceab291dc0264872b074879f932eed Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 15:25:49 +0000 Subject: [PATCH 048/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4c28a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a0a1962..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d0af8fe..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2b83ddf92eb58f2c678d81ecc480e7bd257efbf0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 15:26:33 +0000 Subject: [PATCH 049/120] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 378 -- 37 files changed, 6199 insertions(+), 4197 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 (93%) 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 9446016..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T04:26:25.320Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index c96bb53..b6771e7 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba4c28a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a0a1962 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 bb7737e..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '00i36', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 99d5c75..42734e5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "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..efcf439 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 9e86c5e3c4edf7098e220be7567dfb962605a24f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:48:55 +0000 Subject: [PATCH 050/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..9e46e8f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u,F5', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 5e3a438..99d5c75 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 9abe4e2b2c9fe3737718b43ca60e48e56d56af74 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:53:41 +0000 Subject: [PATCH 051/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 b6771e7..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba4c28a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a0a1962..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '00i36', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index efcf439..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f9944d015edf0d8a73d2781809facc0f61256553 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:54:28 +0000 Subject: [PATCH 052/120] 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 | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 378 -- 39 files changed, 6199 insertions(+), 4196 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 (93%) 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 dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -240,7 +233,7 @@ shape = arrayShape( arr ); ## 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]. @@ -302,7 +295,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6c4327d --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e1a2b51 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 9e46e8f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u,F5', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 99d5c75..42734e5 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.0.6", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "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..a8f1b60 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 7678b22af47f5885dbbd2a661d8faa97928d9ccc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 16:47:25 +0000 Subject: [PATCH 053/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..9e46e8f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u,F5', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index c301316..8654e02 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From b4cce9cf19accb7ebe534da0e709bb88e53f511b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 18:05:04 +0000 Subject: [PATCH 054/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6c4327d..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e1a2b51..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a8f1b60..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2d5b513d5830f554e38037733dc9201f030c5bfb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 18:05:50 +0000 Subject: [PATCH 055/120] 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 | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 378 -- 40 files changed, 6199 insertions(+), 4231 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 (93%) 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 dd48555..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/shape) 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 5800fd4..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/shape) 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 1ca31d5..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: '49 1 * * 4' - - # 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 + + ```
@@ -251,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -313,7 +306,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..21d85a6 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e1a2b51 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;gMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 9e46e8f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u,F5', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 8654e02..8a33c90 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9b91a7b --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 7fa03f7ada247afc6f3c63621c9e382c70513706 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 18:18:38 +0000 Subject: [PATCH 056/120] 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 f577aab..4fdd462 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import arrayShape from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs'; +import arrayShape from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs'; ``` #### arrayShape( arr ) @@ -109,7 +109,7 @@ var shape = arrayShape( arr ); - - - - From 5f9d69c144da4c736721c90572a65a309c5acccd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 13:23:19 +0000 Subject: [PATCH 060/120] 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 | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 378 -- test/test.js | 378 -- 42 files changed, 6199 insertions(+), 4668 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 (93%) 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 b773ea1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T02:56:57.762Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 5cd647d..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: '49 1 * * 4' - - # 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 + + ```
@@ -251,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -313,7 +306,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8316355 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..022e436 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 9e46e8f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u,F5', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 8654e02..8a33c90 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2c2edb2 --- /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 09dfdf9..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From bd137eabab3f78b4f510cd9c081cc849a0d043eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 11:48:16 +0000 Subject: [PATCH 061/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..9e46e8f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u,F5', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index b363f83..3ed09eb 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 0d90170e083dd424a6c465b0851437cab5ac38f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 15:13:06 +0000 Subject: [PATCH 062/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8316355..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 022e436..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2c2edb2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 10be5c8d3a9887f6453a4e7535358bfec63eb67f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 15:13:53 +0000 Subject: [PATCH 063/120] 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 | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 378 -- test/test.js | 378 -- 41 files changed, 6199 insertions(+), 4667 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 (93%) 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 dd48555..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/shape) 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 63f523c..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/shape) 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 5cd647d..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: '49 1 * * 4' - - # 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 + + ```
@@ -251,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -313,7 +306,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bab5d61 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..022e436 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 9e46e8f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u,F5', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 3ed09eb..8a33c90 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..730163c --- /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 09dfdf9..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 468a6b78eee0ad28f5fa01a6d83eb61fdccb1585 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 08:24:18 +0000 Subject: [PATCH 064/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..9e46e8f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u,F5', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index bec0a14..3a7710f 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 3d100ad4fd348f51b26c63154c4f1d9ebe5387f0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 14:43:29 +0000 Subject: [PATCH 065/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bab5d61..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 022e436..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 730163c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c5934f0cd32b96159e943a5722e19053973520d4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 14:44:20 +0000 Subject: [PATCH 066/120] 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 | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 42 files changed, 6199 insertions(+), 4331 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 (93%) 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 be83e6f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T03:04:02.030Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 5cd647d..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: '49 1 * * 4' - - # 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 + + ```
@@ -251,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -313,7 +306,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bab5d61 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..022e436 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 9e46e8f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u,F5', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 3a7710f..8a33c90 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5c73f9f --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From bf95f3fa9fffa3588de1458b1fb880c780e10714 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 07:13:07 +0000 Subject: [PATCH 067/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..9e46e8f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u,F5', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 5262ce2..7459da4 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 5dc3807c5a4eee3523cb47bb3472e97f48e53030 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 02:19:03 +0000 Subject: [PATCH 068/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bab5d61..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 022e436..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5c73f9f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6f371066e2bdbd4e49530d9059919bf55562c1fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 02:19:41 +0000 Subject: [PATCH 069/120] 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 | 35 +- benchmark/benchmark.js | 220 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 42 files changed, 6199 insertions(+), 4326 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 (93%) 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 64243ab..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T03:14:42.561Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 5cd647d..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: '49 1 * * 4' - - # 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 + + ```
@@ -251,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -313,7 +306,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 5e08f75..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bab5d61 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..022e436 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 9e46e8f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u,F5', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 7459da4..8a33c90 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "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..35302db --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 90e3777c360c453793eda997005b64e322dc0a79 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 04:33:13 +0000 Subject: [PATCH 070/120] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 56cc9f5..9c01bb3 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 1ef0d61083eec25d8c0ab8db776435e88c30cd80 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 10:47:12 +0000 Subject: [PATCH 071/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bab5d61..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 022e436..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u,F5', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,WAAYb,IAc1C,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 35302db..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c6c13f0c7df1f8fab00a984ae0fe30157cec9f90 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 10:47:25 +0000 Subject: [PATCH 072/120] 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 | 35 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 43 files changed, 6199 insertions(+), 4332 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 (93%) 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 b093e8e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T02:47:52.042Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 efc2ef5..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: '49 1 * * 4' - - # 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 + + ```
@@ -251,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -313,7 +306,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 2edf2f1..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[esm-url]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ed86daa --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function e(t,n){var i=n[0];return r(i)&&(t.push(i.length),e(t,i)),t}function n(t,e,i,s,a){var l,o,u;for(l=e[i],u=0;u1&&(s.length=n(a,s,1,i,a>2)),s}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ccc6d18 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/string-format';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;8LAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAcnG,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 dbc5432..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 9c01bb3..8a33c90 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6b336da --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From b219128012b4662aaa3b19f38facf0000d3bc929 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 05:00:17 +0000 Subject: [PATCH 073/120] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 56cc9f5..9c01bb3 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 1212dbd4b1dcd109ad849d3eca21a9415fba73f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 10:13:03 +0000 Subject: [PATCH 074/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ed86daa..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function e(t,n){var i=n[0];return r(i)&&(t.push(i.length),e(t,i)),t}function n(t,e,i,s,a){var l,o,u;for(l=e[i],u=0;u1&&(s.length=n(a,s,1,i,a>2)),s}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index ccc6d18..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/string-format';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;8LAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAcnG,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6b336da..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5b767435efc2b3669491f9ad71ccb1dfef3f503d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 10:13:18 +0000 Subject: [PATCH 075/120] 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 | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 43 files changed, 6199 insertions(+), 4337 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 (93%) 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 c9fc37a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T03:22:10.200Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 efc2ef5..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ed86daa --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function e(t,n){var i=n[0];return r(i)&&(t.push(i.length),e(t,i)),t}function n(t,e,i,s,a){var l,o,u;for(l=e[i],u=0;u1&&(s.length=n(a,s,1,i,a>2)),s}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ccc6d18 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/string-format';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;8LAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAcnG,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 dbc5432..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 9c01bb3..8a33c90 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c719b89 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 0e3e92510022a419dfcad645990cfcc6aa31da56 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 08:56:14 +0000 Subject: [PATCH 076/120] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 31882e5..5c79381 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From b1dfa98e5443411e7a9bda4966283937c4f23440 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 17:42:34 +0000 Subject: [PATCH 077/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6236 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ed86daa..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function e(t,n){var i=n[0];return r(i)&&(t.push(i.length),e(t,i)),t}function n(t,e,i,s,a){var l,o,u;for(l=e[i],u=0;u1&&(s.length=n(a,s,1,i,a>2)),s}export{i as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index ccc6d18..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/string-format';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;8LAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAcnG,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c719b89..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From abeb480b4ee7bb998f8f4cfb98a256355e40284c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 17:42:52 +0000 Subject: [PATCH 078/120] 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 | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 42 files changed, 6199 insertions(+), 4340 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 (93%) 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 dd48555..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/shape) 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 63f523c..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/shape) 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 6b4dedb..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ed86daa --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function e(t,n){var i=n[0];return r(i)&&(t.push(i.length),e(t,i)),t}function n(t,e,i,s,a){var l,o,u;for(l=e[i],u=0;u1&&(s.length=n(a,s,1,i,a>2)),s}export{i as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..ccc6d18 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/string-format';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;8LAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAcnG,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 dbc5432..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 5c79381..1e9bf65 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..63bb337 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 71fcbbc2b099a935061973f223b897fcce89cf76 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 20:56:32 +0000 Subject: [PATCH 079/120] 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 e76c327..8c57199 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import arrayShape from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs'; +import arrayShape from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.0-esm/index.mjs'; ``` #### arrayShape( arr ) @@ -109,7 +109,7 @@ var shape = arrayShape( arr ); - - - - From eafe200ffa4c0cdadf80db52a766cf11be6329dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 18:18:33 +0000 Subject: [PATCH 083/120] 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 | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 55 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 42 files changed, 4864 insertions(+), 4334 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 (93%) 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 dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bd1dcd0 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 55b9f23..00c9df0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Determine (nested) array dimensions.", "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,34 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b224d3e --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 039b1ce72db586596faa936cf7d5183b3343bfa4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 24 Feb 2024 19:06:11 +0000 Subject: [PATCH 084/120] 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 c2e5de3..ef08a6e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import arrayShape from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs'; +import arrayShape from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.1-esm/index.mjs'; ``` #### arrayShape( arr ) @@ -109,7 +109,7 @@ var shape = arrayShape( arr ); - - - - From 8040ff3953e34d4a462cc0cd8e97ae8d53075716 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 08:55:00 +0000 Subject: [PATCH 088/120] 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 | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 43 files changed, 4864 insertions(+), 4337 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 (93%) 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 0869159..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T03:17:43.889Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..78e8bb3 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index b552c01..00c9df0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f0ca3e0 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From d7e1a06f0e137e3e162873389923e569a69206a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 04:01:55 +0000 Subject: [PATCH 089/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..3b62e15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 0c14b3c..b552c01 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 1cdddfa1f3f15fa1eb900366c918ad73c9ba828d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 08:33:01 +0000 Subject: [PATCH 090/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 78e8bb3..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9884c10..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f0ca3e0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c04f68744fa1e1b40fbff9be706d98a5f775f72c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 08:33:15 +0000 Subject: [PATCH 091/120] 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 | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 43 files changed, 4864 insertions(+), 4340 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 (93%) 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 82f7e31..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T02:42:23.685Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..78e8bb3 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index b552c01..00c9df0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f0ca3e0 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From a9d454ebb0993bcfbe7744aea63b7d598d643822 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 00:12:05 +0000 Subject: [PATCH 092/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..3b62e15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 0c14b3c..b552c01 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 6bb667859e4bb8caf3b73c2d95dab20e11782e0a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 05:17:00 +0000 Subject: [PATCH 093/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 78e8bb3..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9884c10..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f0ca3e0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 421b6a32dde3ff724bc42a1672c7cd30c81c64fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 05:17:17 +0000 Subject: [PATCH 094/120] 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 | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 42 files changed, 4864 insertions(+), 4341 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 (93%) 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 dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..78e8bb3 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index b552c01..00c9df0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f0ca3e0 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From d3da6803b4d23fe75b6a260417a407d3887c999e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 00:58:30 +0000 Subject: [PATCH 095/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..3b62e15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 69227e6..6736b7c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 2e572be14f8db8c420382777e468b36e8539777e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 01:02:20 +0000 Subject: [PATCH 096/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 78e8bb3..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9884c10..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f0ca3e0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5feec3d327e20c439a2c9ef618eb647d1296fdf0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 01:02:35 +0000 Subject: [PATCH 097/120] 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 | 151 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 42 files changed, 4864 insertions(+), 4498 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 (93%) 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 dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e5e410a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 6736b7c..789cd03 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..620ef66 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 60d9a1c38fae053d8835c60206700b93e78ba4fc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 28 Jul 2024 01:04:20 +0000 Subject: [PATCH 098/120] 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 d4d884e..7b41556 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import arrayShape from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs'; +import arrayShape from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs'; ``` #### arrayShape( arr ) @@ -109,7 +109,7 @@ var shape = arrayShape( arr ); - - - - From 3b0dcaef1cd6ec4f33bc2dd00ef53ba24299698a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 08:41:32 +0000 Subject: [PATCH 102/120] 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 | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 43 files changed, 4864 insertions(+), 4488 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 (93%) 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 34b27b0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T03:17:05.157Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..38d9e9b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index fea3a9b..789cd03 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..906e5de --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From e345939e118fbdccc737cff8cbf1571f7e1a3ced Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 19:25:56 +0000 Subject: [PATCH 103/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..3b62e15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 8a83c7e..fea3a9b 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From c52621a1d01bad3d7da470a70a11a6d775052376 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 22:36:12 +0000 Subject: [PATCH 104/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 38d9e9b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9884c10..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 906e5de..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 16d63d6941f51ce2a6d6f67c1f90e4bab3ad0181 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 22:36:30 +0000 Subject: [PATCH 105/120] 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 | 151 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 43 files changed, 4864 insertions(+), 4501 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 (93%) 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 ae5d7bb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T18:26:03.192Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..38d9e9b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index fea3a9b..789cd03 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..906e5de --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From e5922e78417ce114bbd002c2a9558f24054b44cd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 04:42:18 +0000 Subject: [PATCH 106/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..3b62e15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 033c1f2..2c69d1e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 00dd5ea3da9579384d1239f93d5e31c9ec41d159 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:35:17 +0000 Subject: [PATCH 107/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 38d9e9b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9884c10..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 906e5de..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 509e874064f937667e2143d93b99f86cf40409c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:35:33 +0000 Subject: [PATCH 108/120] 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 | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 43 files changed, 4864 insertions(+), 4500 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 (93%) 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 6c918de..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T03:29:15.578Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..38d9e9b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 2c69d1e..789cd03 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..906e5de --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From ce8a0eab273b47171b62b3dd5582540cd67cab30 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 04:51:50 +0000 Subject: [PATCH 109/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..3b62e15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 033c1f2..2c69d1e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 61944c2bc90a67a2194115c5506c03b887a48a95 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:49:10 +0000 Subject: [PATCH 110/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 38d9e9b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9884c10..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 906e5de..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ef5cd8a153dc1fca13d4cd27a2c4c19f9c170421 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:49:21 +0000 Subject: [PATCH 111/120] 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 | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 43 files changed, 4864 insertions(+), 4500 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 (93%) 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 d4ef186..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T03:39:01.490Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ad64184 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e9a4b76 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;yLAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 2c69d1e..789cd03 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cfdf170 --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From b20a33a708b67b8bf5790150771c69100a7b9edb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 04:49:09 +0000 Subject: [PATCH 112/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..3b62e15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 033c1f2..2c69d1e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 6418934254df0920d9f61b8d9bc67a2c7764d979 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:15:08 +0000 Subject: [PATCH 113/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ad64184..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e9a4b76..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;yLAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cfdf170..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bc324c41da900e9c002fc29e9eaa78c7ea4d47d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:15:19 +0000 Subject: [PATCH 114/120] 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 | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 43 files changed, 4864 insertions(+), 4500 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 (93%) 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 e803376..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T03:42:04.142Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..38d9e9b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index 2c69d1e..789cd03 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..906e5de --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 732803975ec81430587ac32c4472f24ddf44d32b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 05:03:19 +0000 Subject: [PATCH 115/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..3b62e15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 35fd4fe..c8c2a21 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 10970c968625fe0af626e445a55c992e35f9d8fb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:45:28 +0000 Subject: [PATCH 116/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 38d9e9b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9884c10..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 906e5de..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 83a782129f693b6935a978a85c69cf67e090c0b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:45:42 +0000 Subject: [PATCH 117/120] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 44 files changed, 4864 insertions(+), 4605 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.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 (93%) 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 4144c58..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T03:46:54.436Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index dd48555..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/shape) 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 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..38d9e9b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index c8c2a21..789cd03 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..906e5de --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); From 97f07e47f2c7a19ebf4935380458acdbea62f628 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:13:31 +0000 Subject: [PATCH 118/120] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbc5432..3b62e15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -116,7 +116,7 @@ function arrayShape( arr ) { var ndims; if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) ); + throw new TypeError( format( '01R2u', arr ) ); } // Initialize the shape/dimensions array: shape = [ arr.length ]; diff --git a/package.json b/package.json index 35fd4fe..c8c2a21 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From b2a44edb3cb4e529c82d7d02b189163bdc55904b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:33:59 +0000 Subject: [PATCH 119/120] Remove files --- index.d.ts | 54 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4901 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 d556f86..0000000 --- a/index.d.ts +++ /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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Determines (nested) array dimensions. -* -* @param arr - array -* @returns array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -declare function arrayShape( arr: ArrayLike ): Array; - - -// EXPORTS // - -export = arrayShape; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 38d9e9b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 9884c10..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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 906e5de..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 61d8e72b298b013bbb722d69dd84655cba1a03ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:34:15 +0000 Subject: [PATCH 120/120] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 150 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 37 +- SECURITY.md | 5 - benchmark/benchmark.js | 220 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 22 - docs/types/test.ts | 43 - examples/index.js | 127 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 58 - lib/main.js | 139 - package.json | 56 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 378 -- 44 files changed, 4864 insertions(+), 4608 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.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 (93%) 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 dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 13907b1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-24T01:06:20.405Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 9e70e94..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/shape) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 63f523c..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/shape) 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 e5d61a4..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: '49 1 * * 4' - - # 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 + + ```
@@ -253,7 +244,7 @@ shape = arrayShape( arr ); ## 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]. @@ -318,7 +309,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/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 2ac33a2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,220 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isArray = require( '@stdlib/assert-is-array' ); -var pkg = require( './../package.json' ).name; -var arrayShape = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3 - arr = [ 1, 2, 3 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 1 ) { - b.fail( 'should return an array of length 1' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3 - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 2 ) { - b.fail( 'should return an array of length 2' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3 - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 3 ) { - b.fail( 'should return an array of length 3' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3 - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 4 ) { - b.fail( 'should return an array of length 4' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d', function benchmark( b ) { - var arr; - var out; - var i; - - // 3x3x3x3x3 - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = arrayShape( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( out ) || out.length !== 5 ) { - b.fail( 'should return an array of length 5' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 1a33c27..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/shape" -%% click B href "https://github.com/stdlib-js/array-shape/tree/main" -%% click C href "https://github.com/stdlib-js/array-shape/tree/production" -%% click D href "https://github.com/stdlib-js/array-shape/tree/esm" -%% click E href "https://github.com/stdlib-js/array-shape/tree/deno" -%% click F href "https://github.com/stdlib-js/array-shape/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/shape -[production-url]: https://github.com/stdlib-js/array-shape/tree/production -[deno-url]: https://github.com/stdlib-js/array-shape/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-shape/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-shape/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-shape/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-shape/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-shape/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 5ad32d4..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import arrayShape from '../docs/types/index'; -export = arrayShape; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 0831a36..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var l=g(function(q,c){ -var u=require('@stdlib/assert-is-array-like-object/dist'),s=require('@stdlib/error-tools-fmtprodmsg/dist');function f(r,e){var t=e[0];return u(t)&&(r.push(t.length),f(r,t)),r}function o(r,e,t,a,h){var v,n,i;for(v=e[t],i=0;i1&&(e.length=o(t,e,1,r,t>2)),e}c.exports=p -});var y=l();module.exports=y; -/** @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 4894fd7..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 isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar format = require( '@stdlib/string-format' );\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Must provide an array-like object. Value: `%s`.', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayShape;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Determine (nested) array dimensions.\n*\n* @module @stdlib/array-shape\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arrayShape = require( '@stdlib/array-shape' );\n*\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\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,EAAoB,QAAS,qCAAsC,EACnEC,EAAS,QAAS,uBAAwB,EAa9C,SAASC,EAASC,EAAOC,EAAM,CAC9B,IAAIC,EAAID,EAAK,CAAE,EACf,OAAKJ,EAAmBK,CAAE,IACzBF,EAAM,KAAME,EAAE,MAAO,EACrBH,EAASC,EAAOE,CAAE,GAEZF,CACR,CAaA,SAASG,EAAOC,EAAOJ,EAAOK,EAAGJ,EAAKK,EAAM,CAC3C,IAAIC,EACAL,EACA,EAMJ,IAHAK,EAAMP,EAAOK,CAAE,EAGT,EAAI,EAAG,EAAIJ,EAAI,OAAQ,IAAM,CAIlC,GAHAC,EAAID,EAAK,CAAE,EAGN,CAACJ,EAAmBK,CAAE,GAAKA,EAAE,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJJ,EAAIC,EAAOC,EAAOJ,EAAOK,EAAE,EAAGH,EAAGG,EAAE,EAAID,EAAM,CAAE,EAC1CF,EAAIE,GAER,OAAOF,CAGV,CACA,OAAOE,CACR,CA8BA,SAASI,EAAYP,EAAM,CAC1B,IAAID,EACAI,EAEJ,GAAK,CAACP,EAAmBI,CAAI,EAC5B,MAAM,IAAI,UAAWH,EAAQ,oEAAqEG,CAAI,CAAE,EAGzG,OAAAD,EAAQ,CAAEC,EAAI,MAAO,EAGrBF,EAASC,EAAOC,CAAI,EACpBG,EAAQJ,EAAM,OAGTI,EAAQ,IAEZJ,EAAM,OAASG,EAAOC,EAAOJ,EAAO,EAAGC,EAAKG,EAAQ,CAAE,GAEhDJ,CACR,CAKAJ,EAAO,QAAUY,ICtFjB,IAAIC,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "format", "recurse", "shape", "arr", "v", "check", "ndims", "d", "flg", "len", "arrayShape", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4f446cc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,22 +0,0 @@ - -{{alias}}( arr ) - Determines array dimensions. - - Parameters - ---------- - arr: ArrayLikeObject - Input array. - - Returns - ------- - out: Array - Array shape. - - Examples - -------- - > var out = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) - [ 2, 3 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 811b8aa..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 arrayShape = require( './index' ); - - -// TESTS // - -// The function returns an array of numbers.. -{ - arrayShape( [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] ); // $ExpectType number[] -} - -// The compiler throws an error if not provided an array-like object... -{ - arrayShape( 5 ); // $ExpectError - arrayShape( false ); // $ExpectError - arrayShape( true ); // $ExpectError - arrayShape( null ); // $ExpectError - arrayShape( undefined ); // $ExpectError - arrayShape( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - arrayShape(); // $ExpectError - arrayShape( [ 1, 2, 3 ], 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 73bf8fd..0000000 --- a/examples/index.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 arrayShape = require( './../lib' ); - -var arr = [ 1, 2, 3 ]; -var shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1 ], - [ 2 ], - [ 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' - -arr = [ - [], - [], - [] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x0' - -arr = [ - [ 1, 2, 3 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x3' - -arr = [ - [ [ 1 ] ], - [ [ 2 ] ], - [ [ 3 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1x1' - -arr = [ [ [ [ 1, 2, 3 ] ] ] ]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '1x1x1x3' - -arr = [ - [ 1, 2 ], - [ 3, 4 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '2x2' - -arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x3' - -arr = [ - [ 1, 2, 3 ], - null, - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ 1, 2, 3 ], - [ [ 4, 5, 6 ] ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ 4, 5, 6 ], - [ [ 7, 8, 9 ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ 1, 2, 3 ] ], - [ [ 4, 5, 6 ] ], - [ 7, 8, 9 ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3' - -arr = [ - [ [ [ 1, 2, 3 ] ] ], - [ [ 4, 5, 6 ] ], - [ [ [ 7, 8, 9 ] ] ] -]; -shape = arrayShape( arr ); -console.log( shape.join( 'x' ) ); -// => '3x1' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 93% rename from docs/types/index.d.ts rename to index.d.ts index d800b46..d556f86 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..cca4751 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function e(t,n){var s=n[0];return r(s)&&(t.push(s.length),e(t,s)),t}function n(t,e,s,i,o){var l,h,f;for(l=e[s],f=0;f1&&(i.length=n(o,i,1,s,o>2)),i}export{s as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9884c10 --- /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 isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// FUNCTIONS //\n\n/**\n* Recursively (and eagerly) attempts to resolve nested array dimensions.\n*\n* @private\n* @param {Array} shape - output array\n* @param {ArrayLikeObject} arr - array\n* @returns {Array} shape array\n*/\nfunction recurse( shape, arr ) {\n\tvar v = arr[ 0 ];\n\tif ( isArrayLikeObject( v ) ) {\n\t\tshape.push( v.length );\n\t\trecurse( shape, v );\n\t}\n\treturn shape;\n}\n\n/**\n* Recursively verifies that all nested arrays have consistent dimensions.\n*\n* @private\n* @param {PositiveInteger} ndims - number of dimensions\n* @param {Array} shape - shape array\n* @param {NonNegativeInteger} d - dimension\n* @param {ArrayLikeObject} arr - array element to verify\n* @param {boolean} flg - boolean indicating whether to continue recursing\n* @returns {NonNegativeInteger} number of consistent dimensions\n*/\nfunction check( ndims, shape, d, arr, flg ) {\n\tvar len;\n\tvar v;\n\tvar i;\n\n\t// Get the size of the current dimension:\n\tlen = shape[ d ];\n\n\t// Ensure that each array element is an array of the same size:\n\tfor ( i = 0; i < arr.length; i++ ) {\n\t\tv = arr[ i ];\n\n\t\t// If the array element is not an array or is not the same size, we have found an inconsistent dimension:\n\t\tif ( !isArrayLikeObject( v ) || v.length !== len ) {\n\t\t\t// `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions:\n\t\t\treturn d;\n\t\t}\n\t\t// Recursively examine nested elements:\n\t\tif ( flg ) {\n\t\t\tv = check( ndims, shape, d+1, v, d+1 < ndims-1 );\n\t\t\tif ( v < ndims ) {\n\t\t\t\t// Propagate the number of consistent dimensions up the recursion chain...\n\t\t\t\treturn v;\n\t\t\t}\n\t\t}\n\t}\n\treturn ndims;\n}\n\n\n// MAIN //\n\n/**\n* Determines (nested) array dimensions.\n*\n* @param {ArrayLikeObject} arr - array\n* @throws {TypeError} must provide an array\n* @returns {Array} array shape\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3, 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*\n* @example\n* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ];\n*\n* var shape = arrayShape( arr );\n* // returns [ 3 ]\n*/\nfunction arrayShape( arr ) {\n\tvar shape;\n\tvar ndims;\n\n\tif ( !isArrayLikeObject( arr ) ) {\n\t\tthrow new TypeError( format( '01R2u', arr ) );\n\t}\n\t// Initialize the shape/dimensions array:\n\tshape = [ arr.length ];\n\n\t// Eagerly determine array dimensions:\n\trecurse( shape, arr );\n\tndims = shape.length;\n\n\t// Check that all array element dimensions are consistent:\n\tif ( ndims > 1 ) {\n\t\t// If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions:\n\t\tshape.length = check( ndims, shape, 1, arr, ndims > 2 );\n\t}\n\treturn shape;\n}\n\n\n// EXPORTS //\n\nexport default arrayShape;\n"],"names":["recurse","shape","arr","v","isArrayLikeObject","push","length","check","ndims","d","flg","len","i","arrayShape","TypeError","format"],"mappings":";;uMAoCA,SAASA,EAASC,EAAOC,GACxB,IAAIC,EAAID,EAAK,GAKb,OAJKE,EAAmBD,KACvBF,EAAMI,KAAMF,EAAEG,QACdN,EAASC,EAAOE,IAEVF,CACR,CAaA,SAASM,EAAOC,EAAOP,EAAOQ,EAAGP,EAAKQ,GACrC,IAAIC,EACAR,EACAS,EAMJ,IAHAD,EAAMV,EAAOQ,GAGPG,EAAI,EAAGA,EAAIV,EAAII,OAAQM,IAAM,CAIlC,GAHAT,EAAID,EAAKU,IAGHR,EAAmBD,IAAOA,EAAEG,SAAWK,EAE5C,OAAOF,EAGR,GAAKC,IACJP,EAAII,EAAOC,EAAOP,EAAOQ,EAAE,EAAGN,EAAGM,EAAE,EAAID,EAAM,IACpCA,EAER,OAAOL,CAGT,CACD,OAAOK,CACR,CA8BA,SAASK,EAAYX,GACpB,IAAID,EACAO,EAEJ,IAAMJ,EAAmBF,GACxB,MAAM,IAAIY,UAAWC,EAAQ,QAASb,IAcvC,OARAF,EAHAC,EAAQ,CAAEC,EAAII,QAGEJ,IAChBM,EAAQP,EAAMK,QAGD,IAEZL,EAAMK,OAASC,EAAOC,EAAOP,EAAO,EAAGC,EAAKM,EAAQ,IAE9CP,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 69d0269..0000000 --- a/lib/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Determine (nested) array dimensions. -* -* @module @stdlib/array-shape -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arrayShape = require( '@stdlib/array-shape' ); -* -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // 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 3b62e15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,139 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Recursively (and eagerly) attempts to resolve nested array dimensions. -* -* @private -* @param {Array} shape - output array -* @param {ArrayLikeObject} arr - array -* @returns {Array} shape array -*/ -function recurse( shape, arr ) { - var v = arr[ 0 ]; - if ( isArrayLikeObject( v ) ) { - shape.push( v.length ); - recurse( shape, v ); - } - return shape; -} - -/** -* Recursively verifies that all nested arrays have consistent dimensions. -* -* @private -* @param {PositiveInteger} ndims - number of dimensions -* @param {Array} shape - shape array -* @param {NonNegativeInteger} d - dimension -* @param {ArrayLikeObject} arr - array element to verify -* @param {boolean} flg - boolean indicating whether to continue recursing -* @returns {NonNegativeInteger} number of consistent dimensions -*/ -function check( ndims, shape, d, arr, flg ) { - var len; - var v; - var i; - - // Get the size of the current dimension: - len = shape[ d ]; - - // Ensure that each array element is an array of the same size: - for ( i = 0; i < arr.length; i++ ) { - v = arr[ i ]; - - // If the array element is not an array or is not the same size, we have found an inconsistent dimension: - if ( !isArrayLikeObject( v ) || v.length !== len ) { - // `d` is one more than the index of the last consistent dimension and thus equal to the number of consistent dimensions: - return d; - } - // Recursively examine nested elements: - if ( flg ) { - v = check( ndims, shape, d+1, v, d+1 < ndims-1 ); - if ( v < ndims ) { - // Propagate the number of consistent dimensions up the recursion chain... - return v; - } - } - } - return ndims; -} - - -// MAIN // - -/** -* Determines (nested) array dimensions. -* -* @param {ArrayLikeObject} arr - array -* @throws {TypeError} must provide an array -* @returns {Array} array shape -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3, 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -* -* @example -* var arr = [ [ 1, 2, 3 ], [ 4, 5, 6 ], null ]; -* -* var shape = arrayShape( arr ); -* // returns [ 3 ] -*/ -function arrayShape( arr ) { - var shape; - var ndims; - - if ( !isArrayLikeObject( arr ) ) { - throw new TypeError( format( '01R2u', arr ) ); - } - // Initialize the shape/dimensions array: - shape = [ arr.length ]; - - // Eagerly determine array dimensions: - recurse( shape, arr ); - ndims = shape.length; - - // Check that all array element dimensions are consistent: - if ( ndims > 1 ) { - // If `check()` returns a value less than `ndims`, trim off the inconsistent dimensions: - shape.length = check( ndims, shape, 1, arr, ndims > 2 ); - } - return shape; -} - - -// EXPORTS // - -module.exports = arrayShape; diff --git a/package.json b/package.json index c8c2a21..789cd03 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Determine (nested) array dimensions.", "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,35 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float64": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..906e5de --- /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 2deb0ff..0000000 --- a/test/test.js +++ /dev/null @@ -1,378 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var arrayShape = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof arrayShape, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided 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() { - arrayShape( value ); - }; - } -}); - -tape( 'the function returns array dimensions (0d)', function test( t ) { - var arr; - - arr = []; - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - arr = [ [] ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ [], [] ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ [] ], [ [] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ [], [], [] ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ [] ] ], [ [ [] ] ], [ [ [] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ [] ] ] ], [ [ [ [] ] ] ], [ [ [ [] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (0d; array-like objects)', function test( t ) { - var arr; - var x; - - arr = new Float64Array( [] ); - t.deepEqual( arrayShape( arr ), [ 0 ], 'returns expected value' ); - - x = new Float64Array( [] ); - arr = [ x ]; - t.deepEqual( arrayShape( arr ), [ 1, 0 ], 'returns expected value' ); - - arr = [ [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 0 ], 'returns expected value' ); - - arr = [ x, x ]; - t.deepEqual( arrayShape( arr ), [ 2, 0 ], 'returns expected value' ); - - arr = [ [ x ], [ x ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 0 ], 'returns expected value' ); - - arr = [ x, x, x ]; - t.deepEqual( arrayShape( arr ), [ 3, 0 ], 'returns expected value' ); - - arr = [ [ [ x ] ], [ [ x ] ], [ [ x ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 0 ], 'returns expected value' ); - - arr = [ [ [ [ x ] ] ], [ [ [ x ] ] ], [ [ [ x ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 0 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d)', function test( t ) { - var arr; - - arr = [ 1 ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 'beep' ]; - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = [ 1, 2 ]; - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = [ 1, 2, 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (1d; array-like object)', function test( t ) { - var arr; - - arr = new Float64Array( [ 1 ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 'beep' ] ); - t.deepEqual( arrayShape( arr ), [ 1 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2 ] ); - t.deepEqual( arrayShape( arr ), [ 2 ], 'returns expected value' ); - - arr = new Float64Array( [ 1, 2, 3 ] ); - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], 3 ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], null ]; - t.deepEqual( arrayShape( arr ), [ 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d)', function test( t ) { - var arr; - - arr = [ [ 1 ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], [ 2 ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - [ 1, 2, 3 ], - [ 4, 5, 6 ], - [ 7, 8, 9 ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (2d; array-like objects)', function test( t ) { - var arr; - - arr = [ new Float64Array( [ 1 ] ) ]; - t.deepEqual( arrayShape( arr ), [ 1, 1 ], 'returns expected value' ); - - arr = [ new Float64Array( [ 1 ] ), [ 2 ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1 ], 'returns expected value' ); - - arr = [ [ 1 ], new Float64Array( [ 2 ] ), [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ new Float64Array( [ 2 ] ) ], [ 3 ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ [ new Float64Array( [ 1 ] ) ], [ [ 2 ] ], [ null ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1 ], 'returns expected value' ); - - arr = [ - new Float64Array( [ 1, 2, 3 ] ), - new Float64Array( [ 4, 5, 6 ] ), - new Float64Array( [ 7, 8, 9 ] ) - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (3d)', function test( t ) { - var arr; - - arr = [ [ [ 1 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ 1 ] ], [ [ 2 ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ 3 ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ null ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1 ], 'returns expected value' ); - - arr = [ - [ [ 1, 1, 1 ], [ 2, 2, 2 ], [ 3, 3, 3 ] ], - [ [ 4, 4, 4 ], [ 5, 5, 5 ], [ 6, 6, 6 ] ], - [ [ 7, 7, 7 ], [ 8, 8, 8 ], [ 9, 9, 9 ] ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (4d)', function test( t ) { - var arr; - - arr = [ [ [ [ 1 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ 1 ] ] ], [ [ [ 2 ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ 3 ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ null ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns array dimensions (5d)', function test( t ) { - var arr; - - arr = [ [ [ [ [ 1 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 1, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 2, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ 1 ] ] ] ], [ [ [ [ 2 ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ 3 ] ] ] ] ]; - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ [ [ [ [ [ 1 ] ] ] ] ], [ [ [ [ [ 2 ] ] ] ] ], [ [ [ [ null ] ] ] ] ]; // eslint-disable-line max-len - t.deepEqual( arrayShape( arr ), [ 3, 1, 1, 1, 1 ], 'returns expected value' ); - - arr = [ - [ - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ], - [ - [ [ 1, 1, 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ], - [ [ 2, 2, 2 ], [ 2, 2, 2 ], [ 2, 2, 2 ] ], - [ [ 3, 3, 3 ], [ 3, 3, 3 ], [ 3, 3, 3 ] ] - ] - ], - [ - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ], - [ - [ [ 4, 4, 4 ], [ 4, 4, 4 ], [ 4, 4, 4 ] ], - [ [ 5, 5, 5 ], [ 5, 5, 5 ], [ 5, 5, 5 ] ], - [ [ 6, 6, 6 ], [ 6, 6, 6 ], [ 6, 6, 6 ] ] - ] - ], - [ - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ], - [ - [ [ 7, 7, 7 ], [ 7, 7, 7 ], [ 7, 7, 7 ] ], - [ [ 8, 8, 8 ], [ 8, 8, 8 ], [ 8, 8, 8 ] ], - [ [ 9, 9, 9 ], [ 9, 9, 9 ], [ 9, 9, 9 ] ] - ] - ] - ]; - t.deepEqual( arrayShape( arr ), [ 3, 3, 3, 3, 3 ], 'returns expected value' ); - - t.end(); -});